HomeWeb Front-endJS TutorialjQuery A plug-in for image switching_jquery

以下是参数说明:

 参数名称  描述
 delay  图片切换速度,单位毫秒
 maskOpacity  遮罩层透明度,1为不透明,0为全透明
 numOpacity  数字按钮透明度,1为不透明,0为全透明
 maskBgColor  遮罩层背景色
 textColor  标题字体颜色
 numColor  数字按钮字体颜色
 numBgColor  数字按钮背景色
 alterColor  数字按钮选中项字体颜色
 alterBgColor  数字按钮选中项背景颜色
插件代码及调用
- 插件名称:ImageScroll
复制代码 代码如下:

(function($){
$.fn.ImageScroll = function(options) {
var defaults = {
delay: 2000,
maskOpacity: 0.6,
numOpacity: 0.6,
maskBgColor: "#000",
textColor: "#fff",
numColor: "#fff",
numBgColor: "#000",
alterColor: "#fff",
alterBgColor: "#999"
};
options = $.extend(defaults, options);
var _this = $(this).css("display", "none");
var _links = [], _texts = [], _urls = [];
var _list = _this.find("a");
var _timer;
var _index = 0;
_list.each(function(index){
var temp = $(this).find("img:eq(0)");
_links.push($(this).attr("href"));
_texts.push(temp.attr("alt"));
_urls.push(temp.attr("src"));
});
if(_list.length return;
}
else {
_this.html("");
}
var _width = _this.width();
var _height = _this.height();
var _numCount = _list.length;
var _numColumn = Math.ceil(_numCount / 2);
var _img = $("").css({"display":"block", "position":"absolute","top":"0px","left":"0px", "z-index":"2", "width":_width "px", "height":_height "px", "background":"url(" _urls[0] ")"}).appendTo(_this);
var _mask = $("
").attr("style","opacity:" options.maskOpacity)
.css({"position":"absolute", "left":"0px", "bottom":"0px", "z-index":"3", "width":_width "px", "height":"46px", "opacity":options.maskOpacity, "background-color":options.maskBgColor}).appendTo(_this);
var _num = $("
").attr("style","opacity:" options.numOpacity)
.css({"position":"absolute", "right":"0px", "bottom":"0px", "z-index":"5", "width":_numColumn*22, "opacity":options.numOpacity, "height":"44px"}).appendTo(_this);
var _text = $("
").css({"position":"absolute", "left":"0px", "bottom":"0px", "z-index":"4", "padding-left":"10px", "height":"44px", "line-height":"44px", "color":options.textColor}).html(_texts[0]).appendTo(_this);
for(var i = 0; i {
$("").html(i 1)
.css({"float":"left", "width":"20px", "height":"20px", "text-align":"center", "background-color":options.numBgColor, "margin":"0px 2px 2px 0px", "cursor":"pointer", "line-height":"20px", "color":options.numColor})
.mouseover(function() {
if(_timer) {
clearInterval(_timer);
}
}).mouseout(function() {
_timer = setInterval(alter, options.delay);
}).click(function(){
numClick($(this));
}).appendTo(_num);
}
var _tempList = _num.find("a");
function alter() {
if(_index > _numCount-1) {
_index = 0;
}
_tempList.eq(_index).click();
}
function numClick(obj) {
var i = _tempList.index(obj);
_tempList.css({"background-color":options.numBgColor, "color":options.numColor});
obj.css({"background-color":options.alterBgColor, "color":options.alterColor});
_img.attr({"href":_links[i], "target":"_blank"})
.css({"opacity":"0", "background":"url(" _urls[i] ")"})
.animate({"opacity":"1"}, 500);
_text.html(_texts[i]);
_index = i 1;
}
setTimeout(alter, 10);
_timer = setInterval(alter, options.delay);
_this.css("display", "block");
};
})(jQuery);

- 调用代码
复制代码 代码如下:





Beautiful scenery picture one
Beautiful landscape pictures two
Beautiful landscape pictures three
Beautiful landscape pictures four
Beautiful landscape pictures five
Beautiful landscape pictures six

<script> <BR>$("#scroll"). ImageScroll(); <BR></script>

- Running results


- Call with parameters

Copy code The code is as follows:

<script> <BR>$("#scroll").ImageScroll({delay:500, maskBgColor:"#ff0000"}); <BR></script>

- Running results

Summary
It’s just a small plug-in, and the customizability may not be very good. You can take a look and modify it. It seems that IE8 still has a small bug, which will be corrected in a while. Upload again. If you find any bugs, please reply and tell me so that I can make corrections in time. If you have any suggestions for optimizing the code, please tell me to help me as a newbie learn, =.=
Statement
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
JavaScript 如何实现图片的左右无缝滑动切换效果?JavaScript 如何实现图片的左右无缝滑动切换效果?Oct 19, 2023 am 08:56 AM

JavaScript如何实现图片的左右无缝滑动切换效果?随着互联网的发展,网页设计中经常会使用图片作为页面的重要元素。而图片的切换效果对于页面的美观度和交互性起着重要的影响。在本篇文章中,我们将探讨如何使用JavaScript实现图片的左右无缝滑动切换效果,并附有具体的代码示例。实现图片的左右无缝滑动切换效果,首先需要做到以下几点:建立一个图片容器,用

如何通过纯CSS实现图片轮播效果的方法和技巧如何通过纯CSS实现图片轮播效果的方法和技巧Oct 18, 2023 am 08:27 AM

如何通过纯CSS实现图片轮播效果的方法和技巧在现代网页设计中,图片轮播效果常常被用于展示多张图片或广告的轮流切换。实现图片轮播效果的方式有很多,其中一种常见的方式是使用CSS动画。本文将介绍如何通过纯CSS实现图片轮播效果的方法和技巧,并提供具体的代码示例。一、HTML结构首先,在HTML中需要准备好用于轮播的图片元素。以下是一个简单的HTML结构示例:&l

如何使用HTML、CSS和jQuery制作一个响应式的图片切换特效如何使用HTML、CSS和jQuery制作一个响应式的图片切换特效Oct 24, 2023 am 08:01 AM

制作响应式的图片切换特效是前端开发中常见的任务之一。在本篇文章中,我们将使用HTML、CSS和jQuery来实现这个特效。下面是详细步骤和具体的代码示例。HTML结构首先,我们需要创建图片切换特效所需的HTML结构。可以使用以下代码示例来创建一个简单的HTML结构。&lt;divclass=&quot;slider-container&quot;&gt;

如何通过Vue实现图片的切换和轮播效果?如何通过Vue实现图片的切换和轮播效果?Aug 18, 2023 pm 04:57 PM

如何通过Vue实现图片的切换和轮播效果?Vue是一种用于构建用户界面的JavaScript框架,它提供了一种优雅而高效的方法来处理Web应用程序中的数据和交互逻辑。Vue的许多强大功能之一就是它可以轻松地处理图片的切换和轮播效果。在本文中,我们将介绍如何使用Vue来实现这些效果。首先,我们需要准备一些基本的HTML结构和样式来展示图片。我们可以使用&lt;i

JavaScript 如何实现图片的左右无缝滑动切换效果同时加入缩放和淡入淡出动画?JavaScript 如何实现图片的左右无缝滑动切换效果同时加入缩放和淡入淡出动画?Oct 25, 2023 am 09:39 AM

JavaScript如何实现图片的左右无缝滑动切换效果同时加入缩放和淡入淡出动画?在网站开发中,图片的滑动切换效果是非常常见的需求,这里我们将介绍如何使用JavaScript实现一种左右无缝滑动切换效果,同时加入缩放和淡入淡出动画。本文将提供详细的代码示例,让你能够轻松实现该效果。首先,我们需要在HTML中准备一个容器,用于放置图片,并且设置容器的

如何使用 JavaScript 实现图片切换的渐变效果?如何使用 JavaScript 实现图片切换的渐变效果?Oct 21, 2023 am 09:33 AM

如何使用JavaScript实现图片切换的渐变效果?随着互联网的发展,网站设计越来越注重用户体验。图片切换是网站常见的交互效果之一,通过图片的渐变切换可以更好地吸引用户的注意力。本文将介绍如何使用JavaScript实现图片切换的渐变效果,并提供具体代码示例。在开始之前,我们需要准备一些图片资源。假设我们有三张图片,分别是"image1.jpg"、"

如何利用Layui实现图片切换轮播效果如何利用Layui实现图片切换轮播效果Oct 26, 2023 am 11:52 AM

如何利用Layui实现图片切换轮播效果,需要具体代码示例标题:利用Layui实现图片切换轮播效果详解引言:在现代网页设计中,图片切换轮播效果已经成为了常见的元素之一。利用图片轮播可以使网页更加动感和吸引人的效果。本文将以Layui为基础,介绍如何实现图片切换轮播效果,并给出具体的代码示例。一、Layui轮播组件介绍Layui是一款经典的前端UI框架,里面包含

如何利用Layui实现图片切换和拉伸效果如何利用Layui实现图片切换和拉伸效果Oct 25, 2023 am 08:13 AM

如何利用Layui实现图片切换和拉伸效果近年来,随着Web前端技术的迅猛发展,越来越多的框架和库被用于美化和增强网页的功能。其中,Layui是一款非常受欢迎的前端框架,它提供了丰富的UI组件和易于使用的功能扩展。本文将介绍如何利用Layui实现图片切换和拉伸效果,并给出具体的代码示例。一、图片切换效果的实现HTML结构首先,我们需要准备一些HTML结构,用于

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.