给切换网页背景的js插件修改 20
//ThemeswitcherforThemeforestimgPathStart="images/backgrounds/";imgPathEnd=newArray("...
// Themeswitcher for Themeforest
imgPathStart = "images/backgrounds/";
imgPathEnd = new Array("bg_1.png","bg_2.png","bg_3.png","bg_4.png","bg_5.png","bg_6.png","bg_7.png","bg_8.png","bg_9.png");
$(".selector li img").click(function() {
// Save BackgroundNr
backgroundNumber = $(this).attr("data-nr");
// change background settings
$("body").css({background:"url('"+imgPathStart+imgPathEnd[backgroundNumber]+"')"});
});
以上是js文件的内容,用法是在jsp中添加一个模块
<div class="themeswitcher">
<p><i class="icon-cogs"></i></p>
<ul class="selector">
<li><img data-nr="0" src="ts/preview/bg_1.png" /></li>
<li><img data-nr="1" src="ts/preview/bg_2.png" /></li>
<li><img data-nr="2" src="ts/preview/bg_3.png" /></li>
<li><img data-nr="3" src="ts/preview/bg_4.png" /></li>
<li><img data-nr="4" src="ts/preview/bg_5.png" /></li>
<li><img data-nr="5" src="ts/preview/bg_6.png" /></li>
<li><img data-nr="6" src="ts/preview/bg_7.png" /></li>
<li><img data-nr="7" src="ts/preview/bg_8.png" /></li>
<li><img data-nr="8" src="ts/preview/bg_9.png" /></li>
</ul>
</div>
网页上有好几个链接,每次点击链接进入到新界面背景就会还原,求怎么修改能使背景不切换。我的想法是添加缓存,在进入新网页发送的data-nr是空的时候,使用上次变换背景的缓存。没有学过js,求大神指导 展开
imgPathStart = "images/backgrounds/";
imgPathEnd = new Array("bg_1.png","bg_2.png","bg_3.png","bg_4.png","bg_5.png","bg_6.png","bg_7.png","bg_8.png","bg_9.png");
$(".selector li img").click(function() {
// Save BackgroundNr
backgroundNumber = $(this).attr("data-nr");
// change background settings
$("body").css({background:"url('"+imgPathStart+imgPathEnd[backgroundNumber]+"')"});
});
以上是js文件的内容,用法是在jsp中添加一个模块
<div class="themeswitcher">
<p><i class="icon-cogs"></i></p>
<ul class="selector">
<li><img data-nr="0" src="ts/preview/bg_1.png" /></li>
<li><img data-nr="1" src="ts/preview/bg_2.png" /></li>
<li><img data-nr="2" src="ts/preview/bg_3.png" /></li>
<li><img data-nr="3" src="ts/preview/bg_4.png" /></li>
<li><img data-nr="4" src="ts/preview/bg_5.png" /></li>
<li><img data-nr="5" src="ts/preview/bg_6.png" /></li>
<li><img data-nr="6" src="ts/preview/bg_7.png" /></li>
<li><img data-nr="7" src="ts/preview/bg_8.png" /></li>
<li><img data-nr="8" src="ts/preview/bg_9.png" /></li>
</ul>
</div>
网页上有好几个链接,每次点击链接进入到新界面背景就会还原,求怎么修改能使背景不切换。我的想法是添加缓存,在进入新网页发送的data-nr是空的时候,使用上次变换背景的缓存。没有学过js,求大神指导 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询