Popup Javascript (Scrolling)
Bonjour, j'aurais une question pour mon premier post sur le forum.
J'ai un popup qui s'ouvre avec du contenu html dedans et j'aimerais lui fixer une
hauteur de 500px par exemple et ajouter une scrollbar.
Voici mon code JS:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
/When you click on a link with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size
//Pull Query & Variables from href URL
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>');
//Define margin for center alignment (vertical horizontal) - we add 80px to the height/width to accomodate for the padding and border width defined in the css
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
//Fade in Background
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
return false;
});
//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove(); //fade them both out
});
return false;
});
}); |
Ej'ai ce bout de code à inserer pour justement avoir une "max-height" et ajouter une scrollbar.
Code:
1 2 3 4 5 6 7 8
|
// Check if window height is smaller than popup height:
if $(window).height()<$('#'+popID).outerHeight() {
// Work out new popup height ( screen height minus popup padding/border widths )
var popupHeight = $(window).height() ($('#'+popID).outerHeight()-$('#'+popID).height());
// Set new popup height and add a scrollbar:
$('#'+popID).css('height', popupHeight).css('overflow-y','scroll');
} |
Mais le code ne fonctionne pas. Si quelqu'un pourrait me donner un coup de main.
Merci.
Adrian