-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.showwidth.js
More file actions
63 lines (49 loc) · 2 KB
/
jquery.showwidth.js
File metadata and controls
63 lines (49 loc) · 2 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Name: Showwidth.js
* Version: 1.0
* Description: A small script to make a pop-up display the width in pixels of the browser window. Aimed to help developers understand when their responsive/adaptive layout breaks etc.
* License: This is free through the open license agreement, share, care and spread :).
* Author: Johan Wedfelt, check me out on GitHub, https://github.com/DaWoody, or go listen to my music: http://www.woodfieldtheartist.net
*
*/
jQuery(document).ready(function(){
$(window).resize(function(){
/*
* Stating below what I am doing.. this is done every resize as it is now..
*/
//If the pop-up isn't already open, open it!
var showContainer = window.open('', 'showContainer', 'height=100, width=250, status=no, toolbar=no, location=no, menubar=no, titlebar=no');
//Print out some start markup in the pop-up
showContainer.document.write('<header><h1 id="widthText"></h1><header>');
//Define the h1 element in the pop-up
var showContainerH1 = showContainer.document.getElementById("widthText");
//Get the body tag in the pop-up
var showContainerBody = showContainer.document.body;
//calculate the width of the original window
var width = $(window).width();
/*
* Set some styles to the markup of the pop-up.
* Defining some variables for background, color etc
* Change these variables below if u want another layout...
*/
var backgroundColor = '#ccc';
var textColor = 'black';
var textShadow = '1px 1px 2px #fff';
var fontSize = '38px';
var paddingTop = '15px';
var textAlign = 'center';
/*
* Setting the changes to the css with some jQuery...
*/
$(showContainerH1).css({
'color' : textColor,
'font-size' : fontSize,
'text-shadow' : textShadow,
'text-align' : textAlign,
'padding-top' : paddingTop
});
$(showContainerBody).css('background-color', backgroundColor);
//Use jQuery to update the h1 element in the pop-up.
$(showContainerH1).html('Width: '+ width + 'px');
});
});