【发布时间】:2011-03-09 19:45:45
【问题描述】:
我有一个脚本,可以将图像 url 转换为路径,并且可以很好地用于主节点导航上的图像淡入淡出。下面的脚本给了我:
http://localhost/Bar/App_Themes/main/images/Beers-Faded.gif
一旦我更深入地导航一个节点,它会将应用程序路径添加到 url 并且函数失败:
http://localhost/bar/Bar/App_Themes/main/images/Beers-Faded.gif
jQuery:
$(function () {
$('img.fade').each(function () {
var $$ = $(this);
var target = $$.css('background-image').replace(/^url|["]|[\)\(]/g, '');
$$.wrap('<span style="position:relative;"></span>')
.parent() // span elements
.prepend('<img>')
.find('img:first') // selector now new image
.attr('src', target);
console.log(target);
$$.css({
'position': 'absolute',
'left': 0,
'top': this.offsetTop
});
$$.hover(function () {
$$.stop().animate({
opacity: 0
}, 250);
}, function () {
$$.stop().animate({
opacity: 1
}, 250);
});
});
});
图片:
<img class="fade" runat="server" src="~/App_Themes/main/images/Beers-Color.jpg" style="background-image: url('../Bar/App_Themes/main/images/Beers-Faded.gif');" />`
您能帮我找到我为适应站点地图导航而更改的代码部分吗?我的网站只会深入三层。
非常感谢,
詹姆斯。
【问题讨论】:
-
感谢 Nick 整理格式 :)
标签: asp.net jquery css regex url