Код в консоли хрома работает, а если вписать в сайт - то нет
http://goo.gl/pynpv - вот сайт.
В консоли ввожу этот код:
jQuery('.products_row').each(function() {
jQuery(this).find('.product').css("top", function(index) {
var asd = parseFloat(jQuery(this).parent('.products_row').css("height"));
var bsd = parseFloat(jQuery(this).css("height"));
return asd - bsd;
})
});
Все пашет. Этот же код сохраняю на сайте и открываю страничку - приходят нули, т.е. не работает. В чем может быть проблема? |
оберните этот код в эту конструкцию:
jQuery(document).ready(function(){
// тут ваш код
});
|
devote,
Там ужо обернуто - там нужно window load размножить на остальные структуры Итого нижний скрипт (link для ориентации
<link rel="stylesheet" href="http://elsyor.kz/wp-content/themes/MyCuisine/orangebox/css/orangebox.css" type="text/css" />
<script type="text/javascript">
jQuery(document).ready(function() {
var $product_thumb = jQuery('.product_entry');
$product_thumb.hover(function() {
jQuery(this).find('.product_image').stop(true, true).animate({top: -10}, 500).find('img').stop(true, true).animate({opacity: 0.5},500);
}, function(){
jQuery(this).find('.product_image').stop(true, true).animate({top: 0}, 500).find('img').stop(true, true).animate({opacity: 1},500);
});
jQuery(document).bind('oB_init', function(){Cufon.refresh();});
Cufon.replace(".product_image h3", {
hover: true
});
});
jQuery(window).load(function() {
jQuery('div.product_image img').each(function(index, value) {
jQuery('div.product_image > h3')[index].style.cssText="width: " + this.width + "px";
jQuery('.products_row').each(function() {
jQuery(this).find('.product').css("top", function(index) {
var asd = parseFloat(jQuery(this).parent('.products_row').css("height"));
var bsd = parseFloat(jQuery(this).css("height"));
return asd - bsd;
})
});
jQuery("#loader").css("display", "none");
jQuery("#left-area").css("display","block");
});
});
</script>
|
Цитата:
На первый взгляд коды идентичные, но в одном случае первый 'each' сразу закрывается, а во втором оборачивает весь код... Почему? |
jQuery('.products_row').each(function() {
jQuery(this).find('.product').css("top", function() {
return jQuery(this).parent('.products_row').height() - jQuery(this).height();
});
jQuery(this).find('.product_image').each(function() {
var $_this = jQuery(this);
jQuery(this).find('span.upictit').css("width", function() {
return $_this.find('img').width();
});
});
});
вот так укоротил скрипт |
| Часовой пояс GMT +3, время: 20:51. |