第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

寫的好復雜,這里的js怎樣精簡并提高可復用性

寫的好復雜,這里的js怎樣精簡并提高可復用性

qq_sU_4 2016-07-26 12:34:15
<!DOCTYPE?html> <html?lang="en"> <head> ????<meta?charset="UTF-8"> ????<title>Title</title> ????<script?src="jquery.min.js"></script> ????<style> ?*{ ????????????margin:?0; ?padding:?0; ?color:white; ?font-weight:?bold; ?} ????????.slidebox{ ????????????width:500px; ?height:?300px; ?background-color:?pink; ?margin:?30px?auto?0; ?overflow:?hidden; ?position:?relative; ?} ????????.content{ ????????????position:?absolute; ?display:?block; ?width:?1500px; ?height:?300px; ?left:?0; ?top:?0; ?} ????????.content{ ????????????list-style:?none; ?} ????????.content?li{ ????????????float:?left; ?width:?500px; ?height:?300px; ?background-color:?#00bbee; ?} ????????.select{ ????????????display:?block; ?width:?100%; ?height:?30px; ?position:?absolute; ?bottom:?50px; ?text-align:?center; ?list-style:?none; ?} ????????.select?li{ ????????????font-size:?50px; ?display:?inline-block; ?cursor:?pointer; ?} ????????.lt{ ????????????position:?absolute; ?left:?20px; ?top:135px; ?font-size:?30px; ?cursor:?pointer; ?} ????????.gt{ ????????????position:?absolute; ?right:?20px; ?bottom:135px; ?font-size:?30px; ?cursor:?pointer; ?} ????????.select?li,.lt,.gt{ ????????????opacity:?0.6; ?} ????????.lt:hover,.gt:hover{ ????????????opacity:?1; ?} ????????.select?li.active{ ????????????opacity:?1; ?} ????</style> </head> <body> ????<div?class="slidebox"> ????????<ul?class="content"> ????????????<li?style="background-color:?#00ee00"></li> ????????????<li?style="background-color:?#95B8E7"></li> ????????????<li?style="background-color:?goldenrod"></li> ????????</ul> ????????<ul?class="select"> ????????????<li?id="li1"?class="active">.</li> ????????????<li?id="li2">.</li> ????????????<li?id="li3">.</li> ????????</ul> ????????<a?class="lt">&lt;</a> ????????<a?class="gt">&gt;</a> ????</div> </body> <script> ?$(function(){ ????????$(".gt").click(function(){ ????????????var?imgpos=parseInt($(".content").css("left")); ?imgpos-=500; ?if(imgpos<-1000){imgpos=0} ????????????$(".content").css("left",imgpos); ?indexFun(); ?}); ?$(".lt").click(function(){ ????????????var?imgpos=parseInt($(".content").css("left")); ?imgpos+=500; ?if(imgpos>0){imgpos=-1000} ????????????$(".content").css("left",imgpos); ?indexFun(); ?}); ?var?slideFun=function(){ ????????var?imgpos=parseInt($(".content").css("left")); ?imgpos-=500; ?if(imgpos<-1000){imgpos=0} ????????$(".content").css("left",imgpos); ?indexFun(); ?}; ?var?indexFun=function(){ ????????????var?imgpos=parseInt($(".content").css("left")); ?if(imgpos==0){ ????????????????$("#li1").addClass("active").siblings().removeClass("active"); ?}else?if(imgpos==-500){ ????????????????$("#li2").addClass("active").siblings().removeClass("active"); ?}else{ ????????????????$("#li3").addClass("active").siblings().removeClass("active"); ?} ????????} ????var?timer=setInterval(slideFun,1000); ?$(".slidebox").hover( ????????????function(){ ????????????????clearInterval(timer); ?},function(){ ???????????????clearInterval(timer); ?timer=setInterval(slideFun,1000); ?}); ?var?listbtn=$(".select?li"); ?listbtn.each(function(){ ????????????var?index=$(this).index(); ?$(this).hover(function(){ ????????????????$(this).addClass("active").siblings().removeClass("active"); ?$(".content").css("left",-index*500); ?}) ????????}) ????}) </script> </html>
查看完整描述

1 回答

?
慕粉3163795

TA貢獻21條經驗 獲得超6個贊

提高可復用性最簡單的方法就是函數封裝。

查看完整回答
反對 回復 2016-07-30
  • qq_sU_4
    qq_sU_4
    是的,我知道,就是不知道應該怎樣簡化及封裝
  • 慕粉3163795
    慕粉3163795
    這個就靠經驗以及平時寫代碼的時候要有意識的去往這方面靠。
  • 1 回答
  • 0 關注
  • 1751 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號