琴弦文字 - jquery外掛程式

來源:互聯網
上載者:User

標籤:

這是一個基於jquery的琴弦效果外掛程式。

以前曾經見過這個效果,有過嘗試的想法但是當時技能點還不夠。 前天在火車上偶然想起這個,認真思索了一下,一氣呵成 :D

看來最近技能樹點偏的不太遠。

效果展示 用你的滑鼠,划過下面的文字

琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字

The string words.The string words.The string words.The string words.

琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字

The string words.The string words.The string words.The string words.

琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字琴弦文字

The string words.The string words.The string words.The string words.

特地做了ie6的相容,,,也不知道是否可用,再附圖一張:

代碼放在github上,歡迎star...... https://github.com/shalldie/qin

 

使用方式:

1         $(selector).qin({2             offset:22, // default , 最大位移量3             duration:500, // default , 晃動時間4             recline:0.1 // default , 每像素位移量,越小“琴弦繃的越緊”5         });

容器需要給一個定位,如:relative,absolute

 

並不是很複雜的東西,講一下我的思路。

效果:

  1. 滑鼠進入容器,能夠拖動文字。
  2. 被拖動的文字會帶動附近的文字,有一個遞減的拖動距離,越遠被帶動的越少。
  3. 拖到一定程度,文字就會彈回去,有一個晃動的效果。

思路:

  1. 容器內的文字,拆分成一個個span。用mousemove來監聽滑鼠。
  2. 滑鼠在容器內移動多少距離(以mouseenter來確定初始位置),文字也朝同樣的方向,移動同樣的距離。附近的文字距離遞減,最低移動0。
  3. 設定一個最大的移動距離,當滑鼠移動距離超出這個最大值,開始回彈效果。彈動效果用easing 函式來做。

 

Enjoy it!

 

琴弦文字 - jquery外掛程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.