Web Design Forum: Jquery pop up help - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Jquery pop up help need advice on .click() javascript Rate Topic: -----

#1 User is offline   neil0wen 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 734
  • Joined: 19-February 09
  • Reputation: 15
  • Gender:Male
  • Location:East Sussex
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 08 April 2011 - 10:07 AM

Hi,

I got this code to create a popup using jQuery and put it into one of my courses. However I can only get one popup at a time to work within the same Div. Click here to see what I mean: Link

Can anyone help?
0

#2 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 08 April 2011 - 11:37 AM

View Postneil0wen, on 08 April 2011 - 10:07 AM, said:

Hi,

I got this code to create a popup using jQuery and put it into one of my courses. However I can only get one popup at a time to work within the same Div. Click here to see what I mean: Link

Can anyone help?


so basically only popup 1 is working? if so we would need to see the code you have to identify the problem B)
also have you checked that you have changed the popup 2 to open the popup 2 and not accidently named it popup1 or whatever your variable is

Gary

This post has been edited by web-itec: 08 April 2011 - 11:39 AM

0

#3 User is online   terydinho 

  • Go go gadget xhtml
  • Group: Moderators
  • Posts: 2,829
  • Joined: 08-January 09
  • Reputation: 231
  • Gender:Male
  • Location:East London, UK
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 08 April 2011 - 11:48 AM

WOW - such a lot of needless JS for such a simple, simple thing.

Ok - my suggestion - use JQuery!

Then assign a class to each of your a tags...

HTML
<a href="#" class="popup_one">POPUP 1</a>
<a href="#" class="popup_two">POPUP 2</a>

<div id="popupbox1">My popup content goes here</div>

<div id="popupbox2">Popup box 2's content here</div>


CSS
#popupbox1, #popupbox2
{
display:none;
}


JS
$('.popup_one').click(function(){

$('#popupbox1').show();

});

$('.popup_two').click(function(){

$('#popupbox2').show();

});


That is the simplest method and probably one I would use...
0

#4 User is online   zed 

  • Web Guru
  • Group: Moderators
  • Posts: 4,941
  • Joined: 25-May 10
  • Reputation: 703
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 08 April 2011 - 11:50 AM

View Postneil0wen, on 08 April 2011 - 10:07 AM, said:

Hi,

I got this code to create a popup using jQuery and put it into one of my courses. However I can only get one popup at a time to work within the same Div. Click here to see what I mean: Link

Can anyone help?


shouldn't you have a reference to the second popup in your popup.js?
0

#5 User is offline   neil0wen 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 734
  • Joined: 19-February 09
  • Reputation: 15
  • Gender:Male
  • Location:East Sussex
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 08 April 2011 - 03:41 PM

Thanks for your help. As you can no doubt tell I am not a developer, so this code is quite tricky for me. After trying lots of things I still can't get it to work. Below is the code:

HTML

          <div id="popupContact">
		<a id="popupContactClose">x</a>
		<h1>Pop up 1</h1>
		<p id="contactArea">test - popup1</p>
        </div>
        <div id="backgroundPopup"></div>
        
        <div id="popupContact2">
		<a id="popupContactClose2">x</a>
		<h1>Pop up 2</h1>
		<p id="contactArea2">test - popup2</p>
        </div>
        <div id="backgroundPopup2"></div>

        
	    <a href="#" class="popupbox1">Click here</a> to open up a popup. I would like to open a second  
        <a href="#" class="popupbox2">pop up</a> here!


JS
/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".popupbox1").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});














//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup2").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup2").fadeIn("slow");
		$("#popupContact2").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup2").fadeOut("slow");
		$("#popupContact2").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact2").height();
	var popupWidth = $("#popupContact2").width();
	//centering
	$("#popupContact2").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup2").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".popupbox2").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose2").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup2").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});


CSS

border:0pt none;
font-family:inherit;
font-size:100%;
font-style:inherit;
font-weight:inherit;
margin:0pt;
padding:0pt;
vertical-align:baseline;
}
body{
background:#fff none repeat scroll 0%;
line-height:1;
font-size: 12px;
font-family:arial,sans-serif;
margin:0pt;
height:100%;
}
table {
border-collapse:separate;
border-spacing:0pt;
}
caption, th, td {
font-weight:normal;
text-align:left;
}
blockquote:before, blockquote:after, q:before, q:after {
content:"";
}
blockquote, q {
quotes:"" "";
}
a{
cursor: pointer;
text-decoration:none;
}
br.both{
clear:both;
}
#backgroundPopup{
display:none;
position:fixed;
_position:absolute; /* hack for internet explorer 6*/
height:100%;
width:100%;
top:0;
left:0;
background:#000000;
border:1px solid #cecece;
z-index:1;
}
#popupContact{
display:none;
position:fixed;
_position:absolute; /* hack for internet explorer 6*/
height:384px;
width:408px;
background:#FFFFFF;
border:2px solid #cecece;
z-index:2;
padding:12px;
font-size:13px;
}
#popupContact h1{
text-align:left;
color:#6FA5FD;
font-size:22px;
font-weight:700;
border-bottom:1px dotted #D3D3D3;
padding-bottom:2px;
margin-bottom:20px;
}
#popupContactClose{
font-size:14px;
line-height:14px;
right:6px;
top:4px;
position:absolute;
color:#6fa5fd;
font-weight:700;
display:block;
}
#button{
	width: 50px;
	float: left;

}
#backgroundPopup2{
display:none;
position:fixed;
_position:absolute; /* hack for internet explorer 6*/
height:100%;
width:100%;
top:0;
left:0;
background:#000000;
border:1px solid #cecece;
z-index:1;
}
#popupContact2{
display:none;
position:fixed;
_position:absolute; /* hack for internet explorer 6*/
height:384px;
width:408px;
background:#FFFFFF;
border:2px solid #cecece;
z-index:2;
padding:12px;
font-size:13px;
}
#popupContact2 h1{
text-align:left;
color:#6FA5FD;
font-size:22px;
font-weight:700;
border-bottom:1px dotted #D3D3D3;
padding-bottom:2px;
margin-bottom:20px;
}
#popupContactClose2{
font-size:14px;
line-height:14px;
right:6px;
top:4px;
position:absolute;
color:#6fa5fd;
font-weight:700;
display:block;
}
#button2 {
	width: 50px;
	float: left;
}


Any help would be appreciated. Thank you!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users