我正在建立Pinterest克隆。Rails应用4.1.4。
。
当您从索引页面单击大头针时,它将进入“显示”页面。
SHOW页面有一些JavaScript可以调整图片/ DIV的大小。
。
几乎每次我从索引页面单击大头针时,javascript都不会运行(不调整图像大小/ div)。
但是,如果我使用Web浏览器单击REFRESH,则脚本似乎总是可以正常运行(图像/ Div get的大小调整就可以了)。
。
链接到github上的js: https : //github.com/growthcode/pinterest/blob/master/app/assets/javascripts/pins.js.coffee
在Heroku上可以尝试一下: https : //growthcode-pinterest.herokuapp.com/
。
SHOW引脚的html:
<div class="container">
<div class="row">
<div id="showPinContainer" class="col-xs-12">
<div id="showPin" class="well">
<%= image_tag @pin.image, class: "show-image" %>
<p class="description"><%= @pin.description %></p>
<p><%= @pin.user.name %></p>
<% if current_user == @pin.user %>
<%= link_to 'Edit', edit_pin_path(@pin) %> |
<% end %>
<%= link_to 'Back', pins_path %>
</div>
</div>
</div>
</div>
。
我在rails上的coffee脚本中编写了此代码,我将同时列出coffee脚本和它的'Js2coffee'转换。
咖啡脚本:
# Pin Show page
$ ->
# set jQuery object variables
$windowObj = $(window)
$showPinContainer = $("#showPinContainer")
$showPin = $("#showPin")
$showPinImg = $("#showPin img")
$showPinHeight = $("#showPin").outerHeight()
$showPinImgWidth = $showPinImg.outerWidth()
setShowPinContainerHeight = ->
if $showPinHeight > 450
$showPinContainer.outerHeight( $showPinHeight )
else
$showPinContainer.outerHeight( 450 )
setShowPinContainerWidth = ->
if $showPinImgWidth < 200
$showPinImg.outerWidth( 200 )
else if $showPinImgWidth > 300
$showPinImg.outerWidth( 300 )
setShowPinContainerSize = ->
setShowPinContainerHeight()
setShowPinContainerWidth()
setShowPinContainerSize()
。
上述咖啡脚本的Js2coffee.com转换:
$(function() {
var $showPin, $showPinContainer, $showPinHeight, $showPinImg, $showPinImgWidth, $windowObj, setShowPinContainerHeight, setShowPinContainerSize, setShowPinContainerWidth;
$windowObj = $(window);
$showPinContainer = $("#showPinContainer");
$showPin = $("#showPin");
$showPinImg = $("#showPin img");
$showPinHeight = $("#showPin").outerHeight();
$showPinImgWidth = $showPinImg.outerWidth();
setShowPinContainerHeight = function() {
if ($showPinHeight > 450) {
return $showPinContainer.outerHeight($showPinHeight);
} else {
return $showPinContainer.outerHeight(450);
}
};
setShowPinContainerWidth = function() {
if ($showPinImgWidth < 200) {
return $showPinImg.outerWidth(200);
} else if ($showPinImgWidth > 300) {
return $showPinImg.outerWidth(300);
}
};
setShowPinContainerSize = function() {
setShowPinContainerHeight();
return setShowPinContainerWidth();
};
return setShowPinContainerSize();
});
这是我关于堆栈溢出的第一个问题,因此,如果我能提供其他任何有帮助的信息,请告诉我。谢谢!
尝试禁用Turbolinks。有关更多信息,请参见Turbolinks上的《Rails指南》文档。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句