Показать сообщение отдельно
  #1 (permalink)  
Старый 30.07.2014, 21:02
Интересующийся
Отправить личное сообщение для new_developer Посмотреть профиль Найти все сообщения от new_developer
 
Регистрация: 25.07.2014
Сообщений: 28

правильно задать условие
Посоветуйте что можно сделать с якорем, скрипт выглядит так :


//scroll
 
    var theDestinations = $('a[id]');
 
    theDestinations.each(function(i){
 
        var thisDestination =  $(this),
            thisDestinationOffset = thisDestination.offset(),
 
            thisLink = $("a[href='/#" + thisDestination.attr("id") + "']");
 
 
        if(thisLink.length > 0) {
            thisLink.click(function(){
                $('html,body').animate({scrollTop : thisDestinationOffset.top-10}, 1500);
                return false;
            });
        }
    });


2
3
thisLink = $("a[href='/#" + thisDestination.attr("id") + "']"); 
 
// В этой строке слеш перед решёткой чтобы с других разделов сайта на главную ссылалось нормально.. Но проблема когда с главной пробую ссылатся на якорь он его невидит едит до конца страницы. На главной должно быть без слеша, но скрипт под слеш заточен, как быть?)


так постоянно перезагружается браузер


if(location.href="http://testsite.ru/"){
 
        var theDestinations = $('a[id]');
 
        theDestinations.each(function(i){
 
            var thisDestination =  $(this),
                thisDestinationOffset = thisDestination.offset(),
 
                thisLink = $("a[href='#" + thisDestination.attr("id") + "']");
 
 
            if(thisLink.length > 0) {
                thisLink.click(function(){
                    $('html,body').animate({scrollTop : thisDestinationOffset.top-10}, 1500);
                    return false;
                });
            }
        });
 
    } else {
        var theDestinations = $('a[id]');
 
        theDestinations.each(function(i){
 
            var thisDestination =  $(this),
                thisDestinationOffset = thisDestination.offset(),
 
                thisLink = $("a[href='/#" + thisDestination.attr("id") + "']");
 
 
            if(thisLink.length > 0) {
                thisLink.click(function(){
                    $('html,body').animate({scrollTop : thisDestinationOffset.top-10}, 1500);
                    return false;
                });
            }
        });
    }
Ответить с цитированием