也寫個豆瓣的滾動效果。

來源:互聯網
上載者:User

效果可以在http://site.douban.com/about看到,左下邊。它是基於jquery寫的。

 

function wb() {this.init.apply(this, arguments)}wb.prototype = {init: function(obj, opts) {var items_box = typeof obj == 'string' ? document.getElementById(obj) : obj;var items = items_box.getElementsByTagName('li'),len = items.length,h = items[0].offsetHeight;var timer = null;var _this = this;timer = setInterval(function() {_this.set(items[len - 1], 0) items_box.insertBefore(items[len - 1], items[0]);items_box.style.marginTop = -h + 'px';_this.fx( - h, 0,function(x) {items_box.style.marginTop = x + 'px';},function() {_this.fx(0, 1,function(x) {_this.set(items[0], x);})})},3000);},fx: function(f, t, fn, callback) {var D = Date,d = new D,e, T = 320,F = function(x) {return (x /= 0.5) < 1 ? (0.5 * Math.pow(x, 2)) : ( - 0.5 * ((x -= 2) * x - 2))};return e = setInterval(function() {var z = Math.min(1, (new D - d) / T);if (false === fn( + f + (t - f) * F(z)) || z == 1) {if (callback && typeof callback == 'function') callback();clearInterval(e);}},10);},set: function(el, val) {el.style.filter = "alpha(opacity=" + parseInt(val * 100) + ")";el.style.opacity = val;}}window.onload = function() {new wb('list')}

結構去豆瓣網上扣吧。給ul加個ID,然後window.onload = function(){new wb('list')},調用相同的ID就可以了,比如這裡的list.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.