基于jQuery的圖片左右無縫滾動插件
更新時間:2012年05月23日 16:54:15 作者:
基于jQuery的圖片左右無縫滾動插件,需要的朋友可以參考下
在線演示:http://demo.jb51.net/js/2012/myslideLeftRight/
打包下載:http://chabaoo.cn/jiaoben/44973.html
核心代碼:
(function($){
$.fn.extend({
"slidelf":function(value){
value = $.extend({
"prev":"",
"next":"",
"speed":""
},value)
var dom_this = $(this).get(0); //將jquery對象轉換成DOM對象;以便其它函數(shù)中調(diào)用;
var marginl = parseInt($("ul li:first",this).css("margin-left")); //每個圖片margin的數(shù)值
var movew = $("ul li:first",this).outerWidth()+marginl; //需要滑動的數(shù)值
//左邊的動畫
function leftani(){
$("ul li:first",dom_this).animate({"margin-left":-movew},value.speed,function(){
$(this).css("margin-left",marginl).appendTo($("ul",dom_this));
});
}
//右邊的動畫
function rightani(){
$("ul li:last",dom_this).prependTo($("ul",dom_this));
$("ul li:first",dom_this).css("margin-left",-movew).animate({"margin-left":marginl},value.speed);
}
//點擊左邊
$("."+value.prev).click(function(){
if(!$("ul li:first",dom_this).is(":animated")){
leftani();
}
});
//點擊左邊
$("."+value.next).click(function(){
if(!$("ul li:first",dom_this).is(":animated")){
rightani();
}
})
}
});
})(jQuery)
思路:
點擊左邊--
1.將第一個LI向左滑動,滑動的數(shù)值就是LI的寬度。(這里是用負margin-left來實現(xiàn)移動。)
2.滑動完成后,將這個LI插入到整個LI的最后一個(實現(xiàn)無縫滾動)
點擊右邊--
1.將最后一個LI插入到所有LI的第一個,并將其定位到可見區(qū)域之外,(這里用的是margin)
2.再將其滑動到可見區(qū)域。
注意:這里的IF判斷語句,是為了防止連續(xù)點擊“左”或“右”的銨鈕,而出現(xiàn)的BUG;
這判斷的意思:只有當LI不處于動畫狀態(tài)時,才執(zhí)行移動函數(shù)。只要處于動畫狀態(tài),點擊時,任何事都不發(fā)生。
打包下載:http://chabaoo.cn/jiaoben/44973.html
核心代碼:
復制代碼 代碼如下:
(function($){
$.fn.extend({
"slidelf":function(value){
value = $.extend({
"prev":"",
"next":"",
"speed":""
},value)
var dom_this = $(this).get(0); //將jquery對象轉換成DOM對象;以便其它函數(shù)中調(diào)用;
var marginl = parseInt($("ul li:first",this).css("margin-left")); //每個圖片margin的數(shù)值
var movew = $("ul li:first",this).outerWidth()+marginl; //需要滑動的數(shù)值
//左邊的動畫
function leftani(){
$("ul li:first",dom_this).animate({"margin-left":-movew},value.speed,function(){
$(this).css("margin-left",marginl).appendTo($("ul",dom_this));
});
}
//右邊的動畫
function rightani(){
$("ul li:last",dom_this).prependTo($("ul",dom_this));
$("ul li:first",dom_this).css("margin-left",-movew).animate({"margin-left":marginl},value.speed);
}
//點擊左邊
$("."+value.prev).click(function(){
if(!$("ul li:first",dom_this).is(":animated")){
leftani();
}
});
//點擊左邊
$("."+value.next).click(function(){
if(!$("ul li:first",dom_this).is(":animated")){
rightani();
}
})
}
});
})(jQuery)
思路:
點擊左邊--
1.將第一個LI向左滑動,滑動的數(shù)值就是LI的寬度。(這里是用負margin-left來實現(xiàn)移動。)
2.滑動完成后,將這個LI插入到整個LI的最后一個(實現(xiàn)無縫滾動)
點擊右邊--
1.將最后一個LI插入到所有LI的第一個,并將其定位到可見區(qū)域之外,(這里用的是margin)
2.再將其滑動到可見區(qū)域。
注意:這里的IF判斷語句,是為了防止連續(xù)點擊“左”或“右”的銨鈕,而出現(xiàn)的BUG;
這判斷的意思:只有當LI不處于動畫狀態(tài)時,才執(zhí)行移動函數(shù)。只要處于動畫狀態(tài),點擊時,任何事都不發(fā)生。
相關文章
ASP.NET jQuery 實例8 (動態(tài)添加內(nèi)容到DropDownList)
在web應用里,我們經(jīng)常需要通過其他控件的事件觸發(fā)動態(tài)構造DropDownList數(shù)據(jù)內(nèi)容。在這節(jié)中,我們將會看到如何實現(xiàn)通過選擇第一個下來框的內(nèi)容來動態(tài)構造第二個下拉框的內(nèi)容2012-02-02jQuery使用load()方法載入另外一個網(wǎng)頁文件內(nèi)的指定標簽內(nèi)容到div標簽的方法
這篇文章主要介紹了jQuery使用load()方法載入另外一個網(wǎng)頁文件內(nèi)的指定標簽內(nèi)容到div標簽的方法,涉及jQuery中l(wèi)oad方法的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03jquery實現(xiàn)table鼠標經(jīng)過變色代碼
table鼠標經(jīng)過變色的效果想必大家都有見到過吧,其實實現(xiàn)很簡單,在本文有個不錯的示例,感興趣的朋友可以學習下2013-09-09