2015-11-18 11 views
5

EDIT >> Plunker: http://plnkr.co/edit/LY7LUAylvKQ3pIv9lhYM?p=previewjQuery scorrimento: rilevare fine e iniziare

Ho implementato jQuery Scroll per tab-titoli, funziona bene.

enter image description here

Se io sono all'inizio della freccia sul lato sinistro dovrebbe scomparire e quando mi muovo a destra che dovrebbe essere mostrato. Se sono alla fine, la freccia sul lato destro dovrebbe scomparire.

Come è possibile rilevare i punti di inizio e fine? Voglio essere in grado di reagire al ridimensionamento delle finestre.

Questi sono i pulsanti: non

$('#nextTabBtn').click(function() { 
    var $target = $('.tabBoxMantle'); 
    if ($target.is(':animated')) return; 
    $target.animate({ 
     scrollLeft: $target.scrollLeft() + 300 
    }, 800); 
}); 


$('#prevTabBtn').click(function() { 
    var $target = $('.tabBoxMantle'); 
    if ($target.is(':animated')) return; 
    $target.animate({ 
     scrollLeft: $target.scrollLeft() - 300 
    }, 800); 
}); 
+1

Provate ad aggiungere anche il markup o un violino sarà fantastico. – Mayank

+1

inserisci il tuo codice in jsfiddle, puoi trovare la posizione di scorrimento sinistra usando l'evento di scorrimento, quindi imposta come scompare usando css in base alla posizione di scorrimento –

+0

@Mayank Domanda aggiornata, plunker aggiunto. –

risposta

0

sono troppo familiarità con angolare, ma ancora ho dato una prova per risolvere il problema

ho creato la funzione per attivare o disattivare Prec Tab e Tab Avanti Pulsante come segue

function ShowPreviousTabBtn() { // handles prev tab button visibility 
    var $targetScroll = $('.auTabBoxMantle'); 
    if ($targetScroll.scrollLeft() == 0) 
    $('#prevTabBtn').hide(); 
    else 
    $('#prevTabBtn').show(); 
} 
function ShowNextTabBtn() { // handles next tab button visibility 
    var $targetScroll = $('.auTabBoxMantle'); 
    var $scrollwidthtotal = $targetScroll[0].scrollWidth; 
    var $scrolledwidth = $targetScroll.width() + $targetScroll.scrollLeft(); 
    if ($scrollwidthtotal <= $scrolledwidth) 
    $('#nextTabBtn').hide(); 
    else 
    $('#nextTabBtn').show(); 
} 

codice di lavoro completo del vostro app.js è riportata qui sotto

angular.module('myApp', []) 

.controller(

    "MainController", 
    function($scope, $http, $window, $document, $location, $anchorScroll) { 

    $scope.my = {}; 
    $scope.my.title = "jQuery Scroll Example"; 


    $http.get('data.json') 
     .success(function(data) { 
     $scope.my.tabs = data; 
     }); 

    function ShowPreviousTabBtn() { 
     var $targetScroll = $('.auTabBoxMantle'); 
     if ($targetScroll.scrollLeft() == 0) 
     $('#prevTabBtn').hide(); 
     else 
     $('#prevTabBtn').show(); 
    } 

    function ShowNextTabBtn() { 
     var $targetScroll = $('.auTabBoxMantle'); 
     var $scrollwidthtotal = $targetScroll[0].scrollWidth; 
     var $scrolledwidth = $targetScroll.width() + $targetScroll.scrollLeft(); 
     if ($scrollwidthtotal == $scrolledwidth) 
     $('#nextTabBtn').hide(); 
     else 
     $('#nextTabBtn').show(); 
    } 

    // Initially hide the previous Tab button 
    ShowPreviousTabBtn(); 
    // Hiding the Next Tab if the Items div is not overflown 
    ShowNextTabBtn(); 

    $('#nextTabBtn').click(function() { 

     var $target = $('.auTabBoxMantle'); 
     if ($target.is(':animated')) return; 
     $target.animate({ 
     scrollLeft: $target.scrollLeft() + 300 
     }, 800) 
     .promise().done(function() { // used as a callback function for animate 
     ShowPreviousTabBtn(); 
     ShowNextTabBtn(); 
     }); 

    }); 

    $('#prevTabBtn').click(function() { 
     var $target = $('.auTabBoxMantle'); 
     if ($target.is(':animated')) return; 
     $target.animate({ 
      scrollLeft: $target.scrollLeft() - 300 
     }, 800) 
     .promise().done(function() { // used as a callback function for animate 
      ShowPreviousTabBtn(); 
      ShowNextTabBtn(); 
     }); 
    }); 

    } 


); 

Spero che questo funzioni per voi :)

+0

grazie mille, vorresti metterlo sul plunker, non funziona nel mio ambiente. Devo reagire al ridimensionamento delle finestre, questo codice da angolare può capovolgerlo: 'angular.element ($ window) .bind ('ridimensiona', function() { }) –

+0

Prev non funziona dopo, L'ho cambiato in '($ scrollwidthtotal <= $ scrolledwidth)', ora funziona. Potresti aggiornare la tua risposta, in modo che io possa contrassegnarla come corretta? Grazie! –

+0

@Vienna Si prega di controllare il codice aggiornato. – Mayank

Problemi correlati