Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-29-2012, 05:09 AM   PM User | #1
Vigilante23
New Coder

 
Join Date: Aug 2012
Posts: 29
Thanks: 5
Thanked 1 Time in 1 Post
Vigilante23 is an unknown quantity at this point
adding a blocking layer and div

I am trying to add a blocking layer and div activated when a image is clicked. I have this code from a class I took but it is activated from a form post button:

if (valid) {
// Add a blocking layer
$('<div class="blocking"></div>').css({
"height": $(document).height(),
"width": "100%",
"position": "absolute",
"left": "0px",
"top": "0px"
}).appendTo('body');

How would I do something similar but make it activate onClick or something on an image?
Vigilante23 is offline   Reply With Quote
Old 08-29-2012, 08:51 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Code:
function addBlocking() {
   $('<div class="blocking"></div>').css({
      "height": $(document).height(),
      "width": "100%",
      "position": "absolute",
      "left": "0px",
      "top": "0px"
   }).appendTo('body');
}

$('img').click(function() {
   addBlocking();
   ...
});
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
Vigilante23 (08-29-2012)
Old 08-29-2012, 07:27 PM   PM User | #3
Vigilante23
New Coder

 
Join Date: Aug 2012
Posts: 29
Thanks: 5
Thanked 1 Time in 1 Post
Vigilante23 is an unknown quantity at this point
Quote:
Originally Posted by devnull69 View Post
Code:
function addBlocking() {
   $('<div class="blocking"></div>').css({
      "height": $(document).height(),
      "width": "100%",
      "position": "absolute",
      "left": "0px",
      "top": "0px"
   }).appendTo('body');
}

$('img').click(function() {
   addBlocking();
   ...
});
I tried this but nothing happend. I tried it with an onClick, without. Made an ID on the img and tried that but simply nothing is happening when I click on the image. Any ideas or specifications? Sorry if it's obvious I'm really new with javascript and jQuery.
Vigilante23 is offline   Reply With Quote
Old 08-29-2012, 07:46 PM   PM User | #4
harbingerOTV
Senior Coder

 
Join Date: Jan 2005
Location: Memphis, TN
Posts: 1,765
Thanks: 8
Thanked 123 Times in 121 Posts
harbingerOTV will become famous soon enough
are you actually calling jquery in your code?
__________________
Stop making things so hard on yourself.
i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis
harbingerOTV is offline   Reply With Quote
Users who have thanked harbingerOTV for this post:
Vigilante23 (08-29-2012)
Old 08-29-2012, 07:59 PM   PM User | #5
Vigilante23
New Coder

 
Join Date: Aug 2012
Posts: 29
Thanks: 5
Thanked 1 Time in 1 Post
Vigilante23 is an unknown quantity at this point
Quote:
Originally Posted by harbingerOTV View Post
are you actually calling jquery in your code?
That's embarrassing. I wasn't. Thanks. I must've deleted it accidentally somewhere because I did have it.
Vigilante23 is offline   Reply With Quote
Old 08-29-2012, 08:24 PM   PM User | #6
Vigilante23
New Coder

 
Join Date: Aug 2012
Posts: 29
Thanks: 5
Thanked 1 Time in 1 Post
Vigilante23 is an unknown quantity at this point
So how would I got about adding a div on top of that blocking layer?
Vigilante23 is offline   Reply With Quote
Old 08-29-2012, 09:43 PM   PM User | #7
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,600
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
By applying an absolute, relative, or fixed position and giving it a higher z-index than the “blocking” div – or by putting it inside that blocking div.

As a side note: it’s better to apply styles via the stylesheet, not in the JavaScript. After all, that blocking div has a class already so you can easily address that in your CSS file.
__________________
Don’t click this link!
VIPStephan is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:20 PM.


Advertisement
Log in to turn off these ads.