Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Всегда Активный первый элемент страницы (https://javascript.ru/forum/jquery/63877-vsegda-aktivnyjj-pervyjj-ehlement-stranicy.html)

New2017 05.07.2016 22:58

Всегда Активный первый элемент страницы
 
Здравствуйте. Помогите решить задачу.
В jquery не разбираюсь,
нужно чтобы первый элемент на странице был по умолчанию открыт. http://new1.grkmask.ru

Подскажите, пожалуйста, что нужно изменить/добавить?

<script>
            jQuery(document).ready(function($) {
				
				if (jQuery(window).width() > 1024) {
					base_width = $('.strip-menu').attr('data-width');
					count = $('.strip-menu').attr('data-count');
					$('section.strip-item').hover(function(){
						$('.strip-item').css('width', (100-base_width*2)/(count-1)+'%');
						$(this).css('width', base_width*2+'%');
					},function(){
						$('.strip-item').css('width', base_width+'%');				
					});
				}
				if (jQuery(window).width() > 760 && jQuery(window).width() < 1025) {
					jQuery('.wrapped_link').click(function(e) {
						if (!jQuery(this).parents('.strip-item').hasClass('hovered')) {
							base_width = $('.strip-menu').attr('data-width');
							count = $('.strip-menu').attr('data-count');						
							e.preventDefault();
							jQuery('.strip-item').removeClass('hovered');
							jQuery(this).parents('.strip-item').addClass('hovered');
							jQuery('.strip-item').css('width', (100-base_width*2)/(count-1)+'%');
							jQuery(this).parents('.strip-item').css('width', base_width*2+'%');
						}
					});
				}
            });	
        </script>

New2017 05.07.2016 23:35

Цитата:

Сообщение от Rise (Сообщение 421379)
New2017,
}).eq(0).trigger('mouseenter'); // 12

}).eq(0).trigger('click'); // 25

Спасибо большое, работает.
Только содержимое первого элемента не отображается (лого, текст)
И когда убираешь мышку с окна, первый элемент снова закрывается.

рони 05.07.2016 23:36

New2017,
jQuery(document).ready(function($) {
    if (jQuery(window).width() > 1024) {
        var show = function(index) {
            items.css("width", (100 - base_width * 2) / (count - 1) + "%").eq(index).css("width", base_width * 2 + "%")
        };
        base_width = $(".strip-menu").attr("data-width");
        count = $(".strip-menu").attr("data-count");
        var items = $("section.strip-item").hover(function() {
            show(items.index(this))
        }, function() {
            show(0)
        });
        show(0)
    }
    if (jQuery(window).width() > 760 && jQuery(window).width() < 1025) jQuery(".wrapped_link").click(function(e) {
        if (!jQuery(this).parents(".strip-item").hasClass("hovered")) {
            base_width =
                $(".strip-menu").attr("data-width");
            count = $(".strip-menu").attr("data-count");
            e.preventDefault();
            jQuery(".strip-item").removeClass("hovered");
            jQuery(this).parents(".strip-item").addClass("hovered");
            jQuery(".strip-item").css("width", (100 - base_width * 2) / (count - 1) + "%");
            jQuery(this).parents(".strip-item").css("width", base_width * 2 + "%")
        }
    })
});

New2017 05.07.2016 23:59

рони,
Супер, спасибо.
Еще бы добавить отображение лого и текста на первом элементе

рони 06.07.2016 00:10

New2017,
jQuery(document).ready(function($) {
    var items = $("section.strip-item").hover(function() {
            show(items.index(this))
        }, function() {
            show(0)
        }),
        base_width = $(".strip-menu").attr("data-width"),
        count = $(".strip-menu").attr("data-count");

    function show(index) {
        items.css("width", (100 - base_width * 2) / (count - 1) + "%")
        .removeClass("hovered")
        .eq(index).css("width", base_width * 2 + "%")
        .addClass("hovered")
    }
    show(0)
});


Часовой пояс GMT +3, время: 13:42.