PHP速学视频免费教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
本文实例为大家分享了jquery焦点图的实现代码,供大家参考,具体内容如下
nbsp;html> <meta> <title>焦点图</title> <style> img{position: relative;} ul{list-style: none;width: 545px;position: absolute;top: 280px;left: 170px;} li{float: left;width: 20px;line-height: 18px;border: 1px solid #ccc;background-color:#494a93;} a:hover{background-color: red;} a{display: block;width: 20px;line-height: 18px;color: white;text-decoration: none;text-align: center;font-size: 12px;font-family: arial;} p{width: 480px;text-align: center;} </style> @@##@@
这是一段测试文字
<script></script> <script> //方法一:超级简单易懂的方法 /*$("ul li:nth-child(1) a").click(function(event){ $("img").attr("src","images/1.jpg") var imgsrc=$(this).attr("href") $("img").attr("src",imgsrc) $("img").attr("src",$(this).attr("href")) $("ul li:nth-child(1)").css("background-color","red") $("ul li:nth-child(2)").css("background-color","#494a93") $("ul li:nth-child(3)").css("background-color","#494a93") $("ul li:nth-child(4)").css("background-color","#494a93") event.preventDefault(); }) $("ul li:nth-child(2) a").click(function(event){ $("img").attr("src","images/2.jpg") var imgsrc=$(this).attr("href") $("img").attr("src",imgsrc) $("ul li:nth-child(2)").css("background-color","red") $("ul li:nth-child(1)").css("background-color","#494a93") $("ul li:nth-child(3)").css("background-color","#494a93") $("ul li:nth-child(4)").css("background-color","#494a93") event.preventDefault(); }) $("ul li:nth-child(3) a").click(function(event){ $("img").attr("src","images/3.jpg") var imgsrc=$(this).attr("href") $("img").attr("src",imgsrc) $("ul li:nth-child(3)").css("background-color","red") $("ul li:nth-child(2)").css("background-color","#494a93") $("ul li:nth-child(1)").css("background-color","#494a93") $("ul li:nth-child(4)").css("background-color","#494a93") event.preventDefault(); }) $("ul li:nth-child(4) a").click(function(event){ $("img").attr("src","images/4.jpg") var imgsrc=$(this).attr("href") $("img").attr("src",imgsrc) $("ul li:nth-child(4)").css("background-color","red") $("ul li:nth-child(2)").css("background-color","#494a93") $("ul li:nth-child(3)").css("background-color","#494a93") $("ul li:nth-child(1)").css("background-color","#494a93") event.preventDefault(); })*/ //方法二:简化了方法一重复的代码量 ,利用.parent().siblings().find("a")选择到父级的其他兄弟元素 $("ul li a").click(function(event){ /*$("img").attr("src","images/4.jpg")*/ var imgsrc=$(this).attr("href"); $("img").attr("src",imgsrc); $(this).css({"background-color":"red","color":"yellow"}); $(this).parent().siblings().find("a").css({"background-color":"#494a93","color":"white"}); event.preventDefault(); var txt=$(this).attr("title"); console.log(txt); //在控制台输出 $("p").text(txt); }) /*$("ul li a").hover(function(event){ $(this).css("background-color","red"); },function(){ $(this).css("background-color","#494a93") })*/ </script>以上是一个简单地焦点图事例,思路:图片路径写在a标签的href属性里,点击a得到$(this).attr("href");并把这个值给img的src。用简单地jQuery写一个点击事件。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持PHP中文网。
更多简单实现jquery焦点图相关文章请关注PHP中文网!
已抢7215个
抢已抢94862个
抢已抢14828个
抢已抢52097个
抢已抢194768个
抢已抢87281个
抢