【发布时间】:2014-06-05 12:59:08
【问题描述】:
我在 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' %>
当您翻转主图像时,它应该显示翻转图像,但 当我翻转图像时,它只显示翻转图像的 url(即作为文本),我不知道问题是什么......
代码输出是;
<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>
【问题讨论】:
-
我不确定,但似乎问题来自于在 javascript 代码的第一行中为
roll_img的定义加上引号。你还尝试了什么? -
我会试着把这条线写成这样:
var roll_img = <%= @advert.roll_img.url %>; -
能否提供主图的输出。主图像的错误代码应该是问题。
-
@JakeSmith url 需要作为字符串传递,这就是为什么它在引号中
-
@OnurYıldırım 我已将图像输出添加到问题中
标签: javascript ruby-on-rails ruby-on-rails-3 image paperclip