我在rails网站上使用expandablebanners.js,我必须显示翻转图像的代码;
<script type="text/javascript">
var roll_img = "<%= @advert.roll_img.url %>"
var squarecenterbottom = ExpandableBanners.banner("squarecenterbottom", roll_img);
squarecenterbottom.animated = true;
squarecenterbottom.setDirection('down', 'center');
squarecenterbottom.expandOnClick = false;
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded",function(){documentReady=true;});}
else if (!window.onload) window.onload = function(){documentReady=true;}
</script>
主图像显示在页面上;
<%= link_to image_tag(@advert.img(:horizontal) title: @advert.name,),
@advert.target_url, :id => 'squarecenterbottom' %>
当你翻转主图像时,它应该显示翻转图像但是 当我翻转图像时,它只显示翻转图像的网址(即文本),我不知道问题是什么....
代码输出是;
<script type="text/javascript">
var roll_img = "http://localhost:3000/system/adverts/large_imgs/000/000/004/original/1n.jpg?1401967781"
var squarecenterbottom = ExpandableBanners.banner("squarecenterbottom", roll_img );
squarecenterbottom.animated = true;
squarecenterbottom.setDirection('down', 'center');
squarecenterbottom.expandOnClick = false;
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded",function(){documentReady=true;});}
else if (!window.onload) window.onload = function(){documentReady=true;}
</script>
<a href="www.example.com id="squarecenterbottom"><img alt="test22" height="90" src="/system/adverts/imgs/000/000/004/horizontal/2n.jpeg?1401818651" title="test22" width="730" /></a>
</div>
这是文档中的代码,显示了它的工作原理;
<script type="text/javascript">
var squaretopleft = ExpandableBanners.banner("squaretopleft", "images/square_expanded.jpg");
squaretopleft.setCloseImage("images/closebutton.jpg", 'left', 'top');
squaretopleft.animated = true;
squaretopleft.setDirection('up', 'left');
squaretopleft.expandOnClick = false;
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded",function(){documentReady=true;});}
else if (!window.onload) window.onload = function(){documentReady=true;}
</script>
</head>
<body>
<a id="squaretopleft" href="www.yourwebsite.com"><img src="images/square.jpg" /></a>
</body>
</html>
答案 0 :(得分:0)
这可能是路径或HTML结构问题 要检查的事项:
<a>
元素就在<script>
之后。然后有一个</div>
结束标记。你有开场<div>
吗?它们都在<body>
吗?ExpandableBanners
代码设置了onload
和DOMContentLoaded
个侦听器,请尝试将其移至文档的<head>
。/imgs
文件夹下,滚动位于/large_imgs
下。这样可以吗?http://localhost:3000
。 (假设您的原始图像显示正常。)答案 1 :(得分:0)
几点:
var roll_img...
声明<a href="www.example.com