Javascript-форум (https://javascript.ru/forum/)
-   Javascript под браузер (https://javascript.ru/forum/css-html/)
-   -   Код в консоли хрома работает, а если вписать в сайт - то нет (https://javascript.ru/forum/css-html/30764-kod-v-konsoli-khroma-rabotaet-esli-vpisat-v-sajjt-net.html)

across 15.08.2012 01:23

Код в консоли хрома работает, а если вписать в сайт - то нет
 
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;
				})
			});

Все пашет.

Этот же код сохраняю на сайте и открываю страничку - приходят нули, т.е. не работает.

В чем может быть проблема?

devote 15.08.2012 02:17

оберните этот код в эту конструкцию:
jQuery(document).ready(function(){
    // тут ваш код
});

Deff 15.08.2012 02:28

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>

across 15.08.2012 10:42

Цитата:

Сообщение от Deff (Сообщение 197669)
devote,
Там ужо обернуто - там нужно window load размножить на остальные структуры

Спасибо вам огромное. Вчера много раз пытался, в итоге безрезультатно.
На первый взгляд коды идентичные, но в одном случае первый 'each' сразу закрывается, а во втором оборачивает весь код... Почему?

across 15.08.2012 20:38

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, время: 10:39.