梁群嘉
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    ###### tags: `Vue` `店商網頁` {%hackmd BJrTq20hE %} # Vue店商網頁-首頁主視覺效果 會想要寫出最終作業的主視覺最主要的原因是看到了[Line主視覺動畫效果](https://www.youtube.com/watch?v=GWmHLZtX-pk),你看都直接有影片可以看了,最差就是照著寫一定很快就可以寫出來了,但是事情不是笨蛋所想的那麼簡單,那個笨蛋就是我。 首先分析動畫效果: 1.螢幕往下滑動時banner製中縮小 2.banner的圖片會不停切換 ## 螢幕往下滑動時banner製中縮小 這裡的想法是監控螢幕的scrollY值,當Y值大於某個數字之後就把banner縮小製中。 下面是關鍵程式碼,最主要是利用:class="{}" 見下面例子的html第1、2行。 JS ```javascript= methods: { scrollWatch () { // 取得scrollY數值 this.scrollY = window.scrollY } }, mounted () { // 監聽scroll window.addEventListener('scroll', this.scrollWatch) } ``` html ```htmlembedded= <div class="frame d-flex justify-content-center align-item-center position-relative" :class="{ 'frame-short':scrollY > 10 }"> <ul class="bannerGroup px-0" :class="{ 'banner-center': scrollY > 10 }" ref="BannerImages"> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===0}" style="background-image:url(https://upload.cc/i1/2022/03/26/VEKZkG.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===1}" style="background-image:url(https://upload.cc/i1/2022/03/26/hdM1VB.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===2}" style="background-image:url(https://upload.cc/i1/2022/03/27/bytXzS.jpg)"></li> <li class="bannerSpecial d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===3}" style="background-image:url(https://upload.cc/i1/2022/03/27/GMxio4.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===4}" style="background-image:url(https://upload.cc/i1/2022/03/27/7urNmk.jpg)"></li> </ul> </div> ``` SCSS ```sass= .banner-center { position: absolute; top: 100px; transition: all 0.5s; width: 80%; height: 60%; } .frame { min-height: 100vh; transition: all 0.5s; } .frame-short { min-height: 50vh; transition: all 0.5s; } ``` ## banner的圖片會不停切換 ### 1.如果只是兩張圖片切換那只要純CSS就可以達成,範例如下。 運作原理是用兩張圖片淡出到淡入,其中第二張圖片執行的時間點是第一張圖片的動畫效果執行到一半時開始執行動畫效果,最後就會相互疊成兩張圖片輪播的效果,關鍵程式碼是第29行的animation-delay: SCSS ```css= $animationBannerSecond:16s; .banner { position: absolute; top: 0; background-image: url(https://upload.cc/i1/2022/03/26/VEKZkG.jpg); width: 100%; height: 100%; background-repeat: no-repeat; background-size:cover; transition: all 0.5s; animation:bannerCarousel; animation-duration: $animationBannerSecond; animation-timing-function: ease-in; animation-iteration-count: infinite; } .banner2 { position: absolute; top: 0; background-image: url(https://upload.cc/i1/2022/03/26/hdM1VB.jpg); width: 100%; height: 100%; background-repeat: no-repeat; background-size:cover; transition: all 0.5s; animation:bannerCarousel; animation-duration: $animationBannerSecond; animation-timing-function: linear; animation-iteration-count: infinite; animation-delay: $animationBannerSecond * 0.5; } @keyframes bannerCarousel { 0% { opacity: 100%; } 25% { opacity: 50%; } 40% { opacity: 0%; } 60% { opacity: 0%; } 75% { opacity: 50%; } 100% { opacity: 100%; } } } ``` ### 2.如果要3張圖片以上切換就需要加入JS去控制每張圖片出現的時間。 1.imgLen為圖片有多少張,這裡是透過在html標籤內使用ref見下方範例html第1行命名,取得ul內容長度見下方範例JS第17 2.使用setInterval()控制每張圖片動畫開始執行的間隔時間。因為setInterval用的單位是毫秒所以animationDuration是秒數*1000。見下方範例JS第5行,整個動畫效果時間淡入加上淡出時間為6秒,所以每隔3秒就要執行一次動畫,並透過animationAction % imgLen的餘數控制bannerAnimation是否載入見下方範例html第二到六行。 3.所有圖片預設opacity為0見下方範例SCSS第二行,本身也是淡出效果,如果不預設為透明就只會看到最後的兩張圖片互相交換而已。 4.把所有ul圖片疊在一起見下方範例SCSS第六行。 5.淡出動畫效果見下方範例SCSS第二十行。 JS ```javascript= data () { return { animationAction: 0, imgLen: 0, animationDuration: 3000 } } methods: { runAnimation () { setInterval(() => { this.animationAction += 1 }, this.animationDuration) } } , mounted () { this.imgLen = this.$refs.BannerImages.children.length this.runAnimation() } ``` html ```htmlembedded= <ul class="bannerGroup px-0" :class="{ 'banner-center': scrollY > 10 }" ref="BannerImages"> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===0}" style="background-image:url(https://upload.cc/i1/2022/03/26/VEKZkG.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===1}" style="background-image:url(https://upload.cc/i1/2022/03/26/hdM1VB.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===2}" style="background-image:url(https://upload.cc/i1/2022/03/27/bytXzS.jpg)"></li> <li class="bannerSpecial d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===3}" style="background-image:url(https://upload.cc/i1/2022/03/27/GMxio4.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===4}" style="background-image:url(https://upload.cc/i1/2022/03/27/7urNmk.jpg)"></li> </ul> ``` SCSS ```css= $animationDuration:6s; .d-none-slow{ transition: all $animationDuration; opacity: 0; } .bannerGroup { position: relative; width: 100%; li { list-style: none; position: absolute; top: 0; width: 100%; height: 100%; background-repeat: no-repeat; background-size:cover; background-position:center center; } } .bannerAnimation { transition: all $animationDuration; opacity: 1; } ``` ### 3.位什麼不用@keyframs做淡出效果呢? 一開始的確是使用@keyframs做效果,但是不知道什麼原因在gitHubPage上的chrom與edge上圖片漸入漸出的效果不會執行,但是在Firefox與Safari則沒有問題。 [出問題的github版本連結](https://github.com/a121515222/Vue-seventh-week/tree/1efc230e0cac48539008571634918bb2b3d98ff0) ### 4.最後把所有效果集合起來的程式碼 [整份作業的github連結](https://github.com/a121515222/Vue-seventh-week) html [視覺效果的github連結](https://github.com/a121515222/Vue-seventh-week/blob/main/src/views/HomeView.vue) ```htmlembedded= <div class="container-fluid pt-7 px-0"> <div class="frame d-flex justify-content-center align-item-center position-relative" :class="{ 'frame-short':scrollY > 10 }"> <ul class="bannerGroup px-0" :class="{ 'banner-center': scrollY > 10 }" ref="BannerImages"> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===0}" style="background-image:url(https://upload.cc/i1/2022/03/26/VEKZkG.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===1}" style="background-image:url(https://upload.cc/i1/2022/03/26/hdM1VB.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===2}" style="background-image:url(https://upload.cc/i1/2022/03/27/bytXzS.jpg)"></li> <li class="bannerSpecial d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===3}" style="background-image:url(https://upload.cc/i1/2022/03/27/GMxio4.jpg)"></li> <li class="d-none-slow" :class="{'bannerAnimation': animationAction % imgLen ===4}" style="background-image:url(https://upload.cc/i1/2022/03/27/7urNmk.jpg)"></li> </ul> </div> </div> ``` JS ```javascript= data () { return { scrollY: 0, animationAction: 0, imgLen: 0, animationDuration: 3000 } }, methods () { runAnimation () { setInterval(() => { this.animationAction += 1 }, this.animationDuration) }, scrollWatch () { // 取得scrollY數值 this.scrollY = window.scrollY } }, mounted () { // 監聽scroll window.addEventListener('scroll', this.scrollWatch) this.imgLen = this.$refs.BannerImages.children.length this.runAnimation() } ``` CSS ```css= $animationDuration:6s; .d-none-slow{ transition: all $animationDuration; opacity: 0; } .bannerGroup { position: relative; width: 100%; li { list-style: none; position: absolute; top: 0; width: 100%; height: 100%; background-repeat: no-repeat; background-size:cover; background-position:center center; } } .bannerAnimation { transition: all $animationDuration; opacity: 1; } .banner-center { //監測到scrollY的值大於設定值時 使用這個效果 position: absolute; top: 100px; transition: all 0.5s; width: 80%; height: 60%; } .frame { min-height: 100vh; transition: all 0.5s; } .frame-short { min-height: 50vh; transition: all 0.5s; } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully