我想建立一个链接。点击这里获得背景演示。然后单击链接,网页的背景将显示一个图像,该图像是可扩展的。
我有一个可扩展的背景解决方案,在独立;使用以下。
但是,我怎么可能只显示“点击”;才能实现。
<!--Expandable BG code IE 7 +-->
<style>
#bg { position: fixed; top: 0; left: 0; }
.bgwidth { width: 100%; }
.bgheight { height: 100%; }
#page-wrap { position: relative; width: 950px; margin-left: auto; margin-right: auto;; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(function() {
var theWindow = $(window),
$bg = $("#bg"),
aspectRatio = $bg.width() / $bg.height();
function resizeBg() {
if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
$bg
.removeClass()
.addClass('bgheight');
} else {
$bg
.removeClass()
.addClass('bgwidth');
}
}
theWindow.resize(function() {
resizeBg();
}).trigger("resize");
});
</script>
<!--Expandable BG code IE 7 +-->
发布于 2013-09-22 00:59:59
您有以下resize
处理程序
theWindow.resize(function() {
resizeBg();
}).trigger("resize");
如果您想在单击链接时调用它,则可以使用
$('a.link').on('click', function(e){
e.preventDefault();
resizeBg();
});
只需将为click
提供的代码放在/在theWindow.resiz
处理程序之前。还要确保有一个带有类link
的link
标记,如
<a href="#" class="link">Click</a>
并从.trigger("resize");
处理程序中删除resize
,以停止在加载时调用处理程序。
https://stackoverflow.com/questions/18939183
复制相似问题