html代码:
Home > Web Front-end > JS Tutorial > body text

A seamless scrolling plug-in written by myself using jquery_jquery

WBOY
Release: 2016-05-16 16:50:24
Original
1099 people have browsed it

效果图:

A seamless scrolling plug-in written by myself using jquery_jquery 

html代码:

复制代码 代码如下:

无缝滚动,向右滚动



  • A seamless scrolling plug-in written by myself using jquery_jquery

  • f2

  • f3

  • f4

  • f5

  • f6

  • f7



无缝滚动,向左滚动



  • 111111111111

  • 222222222222

  • 3333333333333

  • 4444444444444

  • 5555555555555

  • 6666666666666

  • 7777777777777

  • 8888888888888

  • 9999999999999


无缝滚动,向上滚动



  • 111111111111

  • 222222222222

  • 3333333333333

  • 4444444444444

  • 5555555555555

  • 6666666666666

  • 7777777777777

  • 8888888888888

  • 9999999999999


无缝滚动,向下滚动



  • 111111111111

  • 222222222222

  • 3333333333333

  • 4444444444444

  • 5555555555555

  • 6666666666666

  • 7777777777777

  • 8888888888888

  • 9999999999999


无缝滚动,非ul,li标签组合,向右滚动



111111111111


222222222222


3333333333333


4444444444444


5555555555555


6666666666666


7777777777777


8888888888888


9999999999999



不动



  • 111111111111

  • 222222222222

  • 3333333333333

  • 4444444444444

  • 5555555555555

  • 6666666666666

  • 7777777777777

  • 8888888888888

  • 9999999999999



css代码:
复制代码 代码如下:

ul, li,h1 { margin: 0; padding: 0; list-style-type:none;}
ul,div { height: 200px; border: 1px solid red; width: 300px; padding: 30px;margin:10px;list-style-type:none;}
li,p { height: 30px; line-height: 30px; margin-top: 10px; background-color: Gray; color: Yellow; margin-left:10px;}
#guoul1{ width:1000px; height:188px;margin: 0; padding: 0;}
#guoul1 li{ width:300px; height:188px;margin: 0; padding: 0; margin-left:10px;}

js plug-in code:
Copy code The code is as follows:

; (function ($ ) {
var defaults = {
dir: "left", //none: not moving, up: up, right: right, down: down, right: left
delay: 30, //execute Time
};
$.fn.gysContentDisplay = function (opt) {
opt = $.extend({}, defaults, opt);

//Global variable area
var obj = $(this); //Current object
obj.css({ "overflow": "hidden" }); //Initialization element
if (opt.dir == "none") return ;
var objLis = obj.children(); //Child elements in the object
objLis.css({ "overflow": "hidden" });
var objSize = 0; //Outer frame Size
var scrollEvent = "scrollLeft"; //The scrolling direction of the scroll bar
var liTotalSize = 0, liTotalSizeOther = 0; //The size of each li element (width or height), the total size after cloning
var scrollSize = 0, //The actual distance of the scroll bar
scrollSizeMax = 0, //The maximum distance of the scroll bar
scrollSizeMin = 0; //The minimum distance of the scroll bar
var interval = "" ; //Record setInterval

if (opt.dir == "up" || opt.dir == "down") {//Up and down
objSize = obj.innerHeight();
scrollEvent = "scrollTop";
obj.css({ "padding-top": 0, "padding-bottom": 0 }).height(objSize);
}
else if (opt.dir == "left" || opt.dir == "right") {//Left and left
objSize = obj.innerWidth();
scrollEvent = "scrollLeft";
obj.css({ "padding -left": 0, "padding-right": 0 }).width(objSize);
}
else {
alert("Your dir parameter is wrong");
}

var getChildTotalSize = function (dir) {//Define the method to get the total size of li
if (dir == "left" || dir == "right") {
objLis.css( "float", "left");
return function () {
objLis.each(function () {
liTotalSize = $(this).outerWidth(true);
});
}
}
else if (dir == "up" || dir == "down") {
objLis.css("float", "none");
return function () {
objLis.each(function () {
liTotalSize = $(this).outerHeight(true);
});
}
}
} (opt. dir);
getChildTotalSize(); //Get the total size of all li and assign it in the method

(function () {
var cloneCount = Math.ceil(objSize * 2 / liTotalSize ); //How many times to assign child elements
var cloneHtmlNow = "", cloneHtmlStart = obj.html(); //Original child element string

for (var i = 0; i cloneHtmlNow = cloneHtmlStart;
}
obj.append(cloneHtmlNow);
liTotalSizeOther = (cloneCount 1) * liTotalSize; //Get the length after adding child elements
})();


if (opt.dir == "left" || opt.dir == "right") {
obj.css({ "position": " relative", "z-index": 0 });
obj.children().css({ "position": "absolute", "z-index": 1 });
var left = 0 ;
obj.children().each(function () {
$(this).css({ "left": left "px", "top": 0 });
left = $ (this).outerWidth(true);
});
}


//Scroll bar scrolling method
function scrollChange(dir) {
if (dir == "left" || dir == "up") {
obj[scrollEvent](0);
scrollChange = function () {
scrollSize;
if (scrollSize >= liTotalSize ) scrollSize = 0;
obj[scrollEvent](scrollSize);
}
}
else if (dir == "right" || dir == "down") {
scrollSizeMax = liTotalSizeOther - objSize;
obj[scrollEvent](scrollSizeMax);
scrollSize = scrollSizeMax;
scrollSizeMin = scrollSizeMax - liTotalSize;
scrollChange = function () {
scrollSize--;
if (scrollSize obj[scrollEvent](scrollSize);
}
}
};
scrollChange(opt.dir);
interval = setInterval(scrollChange, opt.delay);
obj.children().on("mouseover", function () {
clearInterval(interval);
}).on("mouseleave", function () {
interval = setInterval(scrollChange, opt.delay);
});
}
})(jQuery);

Plug-in call:
Copy code The code is as follows:

$(function () {
$(" #guoul1").gysContentDisplay({ dir: "right" });
$("#guoul2").gysContentDisplay({ dir: "left" });
$("#guoul3").gysContentDisplay ({ dir: "up" });
$("#guoul4").gysContentDisplay({ dir: "down" });
$("#guoul5").gysContentDisplay({ dir: "right " });
$("#guoul6").gysContentDisplay({ dir: "none" });
})
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!