JavaScript - Preventing A Colour From Getting Too Light To Or Dark
Hey guys, I have a colour picker on my site, see it at http://www.ludatha.com
Now I want to change the colour of the links on the page, don't worry I know how to do all this. It's just if someone chooses full black (#000000) the theme looks awesome, but the links on the dark background are invisible. Similarly if someone chooses full white (#ffffff) then you can't see the text on the white background. So I want to know if you geniuses can make it so when a variable containing a hex, like #000000 is set as the main colour, then the link colour is changed to #666666 so you can still see it, but I want it to work with colours, so if you had #360000 (dark red) then the link colour would be something like #a10000. I know this is possible, somehow... I hope I have explained it well enough for you to understand, here is my code to change the background: Code: onChange: function (hsb, hex, rgb) { $('.colour-picker-colour').css('backgroundColor', '#' + hex); $('.background').css('backgroundColor', '#' + hex); $('.colour').css('backgroundColor', '#' + hex); $('.colour-text').css('color', '#' + hex); $('a .colour-text').css('color', '#' + hex); $('.colour-text-hover:hover').css('color', '#' + hex); $('.tabs a:hover').css('color', '#' + hex); $('.seperator').css('backgroundColor', '#' + hex); $.cookie('ludatha_colour', hex, { expires: 365 }); } P.S. My site may not look right for a few hours as the images and CSS is updating. Similar TutorialsOn various video sites you can click cinema mode and the page goes dark, whilst you watch the video. On my page I have a box which appears, where the user enters their name and email address. But I would like the box to remain active and in view. While the rest of the page goes darker and unusable, Like on the video player websites How do I do this? How do I do this? I've set up javascript to change the background colour depending on what colour square the user clicks on, this is working fine. However, I want to be able to set an initial colour, other than white, and then let the user chose their own. here is my code so far. <script language="JavaScript"> <!-- function changeBGC(color){ document.bgColor = color; } //--> </script> Then on the buttons: <a href="#" onclick="javascript:changeBGC('#486970')"><img src="images/blueSquare.jpg" alt="a" width="25" border="0" /></a> <a href="#" onclick="javascript:changeBGC('#dd737b')"><img src="images/pinkSquare.jpg" alt="x" width="25" /></a> <a href="#" onclick="javascript:changeBGC('#4f814e')"><img src="images/greenSquare.jpg" alt="cx" width="25" /></a> <a href="#" onclick="javascript:changeBGC('#594b31')"><img src="images/brownSquare.jpg" alt="s" width="25" /></a> <a href="#" onclick="javascript:changeBGC('#ffffff')"><img src="images/whiteSquare.jpg" alt="x" width="25" /></a> I want the page to be initially set to the brown colour, then I want the user to be able to choose their own colour. Thanks for any help. Hi, I need some advice. I wanted to create a 4 by 4 grid in a webpage. Then i want to select a specific box in the grid to flash a certain colour. There will always be a set sequence of the same sections lighting up with the same colours. So row 2 col 2 flashes green, then row 4 col 1 flashes pink etc. With around 5 boxes being used out of 16. How would i go about doing this? Is using Javascript the best thing to use? Any advice would be greatly appreciated. Thanks. Im doing a project for college and on my website im trying to install lightbox on this page www.corkbouncingcastles.com/castles.html Can anyone help me out? in the image.xml file i have this code.. do i need to change the part where it says target="_self" ?? PHP Code: <photo image="images/small/02.jpg" bigimage="images/big/02.jpg" url="javascript:GroupDelegate('img2')" target="_self" lightboxInfo="Optional description for image 2"><![CDATA[Super Slide Bouncing Castle]]></photo> Hello I have a primitive Web page he http://stevehigham59.7host.com/final...u//index4.html At the very bottom there is a blue link labelled 'Demo' which, when clicked loads a light-box. The script behind this 'Demo' link is simply: Code: <div id="contact-form"> <a class="contact" href="#">Demo</a></div> This references a JS file (contact.js) which I am pasting below this message. What I would like to do is load the light-box into a simple list (the menu tab) which appears on the same page as the URL I have posted above. The script behind the menu tab was something like: <li><a href="http://www.mysite.com">Contact</a></li> but I changed it to: <li><a class="contact" href="#">Contact</a></li> This didn't work because it is not speaking to the JS file (I presume). How can I achieve what I am after, please? Thanks. Steve contact.js Code: $(document).ready(function () { $('#contact-form input.contact, #contact-form a.contact').click(function (e) { e.preventDefault(); // load the contact form using ajax $.get("data/contact.php", function(data){ // create a modal dialog with the data $(data).modal({ closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>", position: ["15%",], overlayId: 'contact-overlay', containerId: 'contact-container', onOpen: contact.open, onShow: contact.show, onClose: contact.close }); }); }); // preload images var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png']; $(img).each(function () { var i = new Image(); i.src = 'img/contact/' + this; }); }); var contact = { message: null, open: function (dialog) { // add padding to the buttons in firefox/mozilla if ($.browser.mozilla) { $('#contact-container .contact-button').css({ 'padding-bottom': '2px' }); } // input field font size if ($.browser.safari) { $('#contact-container .contact-input').css({ 'font-size': '.9em' }); } // dynamically determine height var h = 280; if ($('#contact-subject').length) { h += 26; } if ($('#contact-cc').length) { h += 22; } var title = $('#contact-container .contact-title').html(); $('#contact-container .contact-title').html('Loading...'); dialog.overlay.fadeIn(200, function () { dialog.container.fadeIn(200, function () { dialog.data.fadeIn(200, function () { $('#contact-container .contact-content').animate({ height: h }, function () { $('#contact-container .contact-title').html(title); $('#contact-container form').fadeIn(200, function () { $('#contact-container #contact-name').focus(); $('#contact-container .contact-cc').click(function () { var cc = $('#contact-container #contact-cc'); cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked'); }); // fix png's for IE 6 if ($.browser.msie && $.browser.version < 7) { $('#contact-container .contact-button').each(function () { if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) { var src = RegExp.$1; $(this).css({ backgroundImage: 'none', filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '", sizingMethod="crop")' }); } }); } }); }); }); }); }); }, show: function (dialog) { $('#contact-container .contact-send').click(function (e) { e.preventDefault(); // validate form if (contact.validate()) { var msg = $('#contact-container .contact-message'); msg.fadeOut(function () { msg.removeClass('contact-error').empty(); }); $('#contact-container .contact-title').html('Sending...'); $('#contact-container form').fadeOut(200); $('#contact-container .contact-content').animate({ height: '80px' }, function () { $('#contact-container .contact-loading').fadeIn(200, function () { $.ajax({ url: 'data/contact.php', data: $('#contact-container form').serialize() + '&action=send', type: 'post', cache: false, dataType: 'html', success: function (data) { $('#contact-container .contact-loading').fadeOut(200, function () { $('#contact-container .contact-title').html('Thank you!'); msg.html(data).fadeIn(200); }); }, error: contact.error }); }); }); } else { if ($('#contact-container .contact-message:visible').length > 0) { var msg = $('#contact-container .contact-message div'); msg.fadeOut(200, function () { msg.empty(); contact.showError(); msg.fadeIn(200); }); } else { $('#contact-container .contact-message').animate({ height: '30px' }, contact.showError); } } }); }, close: function (dialog) { $('#contact-container .contact-message').fadeOut(); $('#contact-container .contact-title').html('Goodbye...'); $('#contact-container form').fadeOut(200); $('#contact-container .contact-content').animate({ height: 40 }, function () { dialog.data.fadeOut(200, function () { dialog.container.fadeOut(200, function () { dialog.overlay.fadeOut(200, function () { $.modal.close(); }); }); }); }); }, error: function (xhr) { alert(xhr.statusText); }, validate: function () { contact.message = ''; if (!$('#contact-container #contact-name').val()) { contact.message += 'Name is required. '; } var email = $('#contact-container #contact-email').val(); if (!email) { contact.message += 'Email is required. '; } else { if (!contact.validateEmail(email)) { contact.message += 'Email is invalid. '; } } if (!$('#contact-container #contact-message').val()) { contact.message += 'Message is required.'; } if (contact.message.length > 0) { return false; } else { return true; } }, validateEmail: function (email) { var at = email.lastIndexOf("@"); // Make sure the at (@) sybmol exists and // it is not the first or last character if (at < 1 || (at + 1) === email.length) return false; // Make sure there aren't multiple periods together if (/(\.{2,})/.test(email)) return false; // Break up the local and domain portions var local = email.substring(0, at); var domain = email.substring(at + 1); // Check lengths if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255) return false; // Make sure local and domain don't start with or end with a period if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain)) return false; // Check for quoted-string addresses // Since almost anything is allowed in a quoted-string address, // we're just going to let them go through if (!/^"(.+)"$/.test(local)) { // It's a dot-string address...check for valid characters if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local)) return false; } // Make sure domain contains only valid characters and at least one period if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1) return false; return true; }, showError: function () { $('#contact-container .contact-message') .html($('<div class="contact-error"></div>').append(contact.message)) .fadeIn(200); } }; I'm wondering if theirs a way to make a dim light, sorta like a candle follow my mouse cursor on a webpage?
I'm helping out my friend complete her site. check it out he http://themodline.com/clients/jcevent when you head over to the portfolio section the the lightbox script doesnt work properly. but if you just go to http://themodline.com/clients/jcevent/portfolio.html -it works fine. are the scripts mixing up? i made sure i got the correct codes. i made sure the script files are correctly linked. check out my scripts. they are zipped he http://www.themodline.com/clients/jcevent/scripts.zip thanks for the help guys. hope this makes sense! Im trying to figure out how to create a light box that doesn't close to reveal the content on the website, unless the user fully completes atleast 2-3 CPA(Cost Per Action) offers that will pop up in the lightbox? i know how to make a lightbox with a plugin from wordpress, but I just don't know how to make it so it'll close when it figures out the user has completed the surveys/offers. Kind of like this but maybe smaller to show there is content/download link behind it, http://sharecash.org/download.php?file=1595911 Have problem with IE8. Before IE 8, I can disable a drop-down box, but the selected item still there highlighted. But IE 8 makes the highlight go away. Is there any way to keep the original, Disable a item, you still keep the lightlights Thanksl
I am currently using the JavaScript Light Box found on; http://www.huddletogether.com/projects/lightbox2/ I was wondering if it is possible, or easy enough to create something alike the one found on; http://www.whsmith.co.uk/Support/Hel...ffiliates.aspx when you click on; > How to become an affiliate > Complete the OMGuk.com affiliate application form. Many Thanks, Tim Hi there, Where I work there are certain dates where nothing can be done, certain times where work can be done with caution, and dates where work can be done. I want to put on the site a traffic light that would change colours based on the calendar dates where work can/can't be done. For example, if April 11th there is stuff to do, the traffic light would be green. But April 12th, there isn't work to do, it would turn red. Do you know how I would go about doing this? If a negative number is entered into the reading variable it should be displayed as a zero. This works with the first calculations such as average but right at they very end the the alert wont display the highest average it just displays the one which has a negative number typed in to it. Code: var region=0 var reading=0 var average=0 var count=0 var readingSum=0 var catergory=0 var dry=0 var normal=0 var wet=0 var countWet=0 var countNormal=0 var countDry=0 var totalLoop=0 var numLocations=0 var maxAverage=0 var maxRegion=0 var maxReadings=0 var totalReadings=0 // ** Find out how many locations ** // numLocations=eval(prompt("How many locations are you taking readings for?")); // ** Loop for multiple entries ** // for(totalLoop=1; totalLoop<=numLocations; totalLoop=totalLoop+1) { // ** Reset total for loop ** // readingSum=0 // ** Get Region ** // region = prompt("Enter region please"); // ** Get Readings ** // totalReadings = eval(prompt("Enter readings please")); // ** Get readings and Prevent negative number ** // if(totalReadings<=0) { alert("Please enter valid reading") } else { alert("You entered " + totalReadings); } // ** Ask for indivdual readings ** // for(count=1; count<=totalReadings; count=count+1) { reading=eval(prompt("Enter reading please")); // ** Prevent negative number ** // if(reading<0) { reading=0 alert("Please enter valid reading") } // ** Work out Total of readings ** // readingSum= readingSum + reading } // ** Work out average ** // average= readingSum/totalReadings // ** Put average into a category and display everything ** // if(average<5) { catergory="dry" countDry=countDry+1 } else if(average>=5 && average<20) { catergory="normal" countNormal= countNormal+1 } else if(average>20) { catergory="wet" countWet=countWet+1 } alert("Location is " + region + "\nNumber of weakly readings taken is " + totalReadings + "\nTotal of readings is " + readingSum + "\nAverage is " + average + "\nLocation is " + catergory); // ** Find Highest average ** // if((average>maxAverage) || (totalReadings>maxReadings)) { maxAverage=average maxRegion=region } } // ** Final Report ** // alert("Number of locations is " + numLocations + "\nDry is " + countDry + "\nNormal is " + countNormal + "\nWet is " + countWet + "\nLocation with highest average reading is " + maxRegion + "\nHighest average is " + maxAverage); Do i need a while loop? i am only allowed to use while, for and if statements is there js to prevent malicious clickers who try to ban my site from google ads by clicking so many times?
How can I go about making it so JavaScript will not let a form submit unless a number entered into a field matches a pre-specified number? A guess.. Code: function validateForm() { if (document.forms["form"]["number"].value=="123") { submit} else {alert ("Cant submit because the number doesn't match."); return false; } } Hello All, How can I prevent a browser from letting an image drag. I've tried this snippet: Code: document.onmousemove = function() {return false}; Thanks in advance! Hi there! I am using GlassBox "http://www.glassbox-js.com/" As a light box on a website. Basically, You click an thumbnail image, and a window pops up with a larger version of that image. Now originally, the window opened X number of pixels from the top of the page. However, My thumbnail images were located mid page, so when you clicked on one, the window would open at the top of the page and the user would not see it unless they scrolled up. So I attempted to modify the script so that it would get the users page width/height and display it directly in the center no matter the position. Now my problem is that the script only works when the user has already scrolled down. So if the page is scrolled all the way to the top, and you click on a thumbnail, the window will not open center screen. Here is an example: http://synaxis.pcriot.com/ When the page loads, DO NOT scroll it, and click on the image. You will see the window pop up, and not centered, like it should be. However, now if you scroll down, and click the image again, you see that it is now centered. I also noticed that when the page is scrolled up, and the image does not center, it always is placed below the thumbnail image, or otherwise where ever the DIV is located. It normally located under the image, but if i place the DIV at the top of the page then the window will pop up there. And this does happen on every browser that I have tested, Firefox, IE, and Chrome. So, I am pretty much stumped as to why this is happening. If anyone can shed some light I would be very grateful. Thank You Here is a link to the original code: http://synaxis.pcriot.com/javascript...ox/glassbox.js And modified code: http://synaxis.pcriot.com/javascript...ox/glassbox.js The modified code is at the very bottom of the script. Original Code: Code: /** * @public */ if ( typeof($) == 'undefined' ) { $ = function (id) { return document.getElementById(id); } } Modified Code Code: /** * @private */ var removeElement = function(id) { var Node = document.getElementById(id); Node.parentNode.removeChild(Node); } /** * @private */ var getDocHeight = function() { var db = document.body; var ddE = document.documentElement; return Math.max( db.scrollHeight, db.offsetHeight, db.clientHeight, ddE.scrollHeight, ddE.offsetHeight, ddE.clientHeight ); } /** * @public */ if ( typeof($) == 'undefined' ) { $ = function (id) { return document.getElementById(id); } } I have been hard at work coding a fancy JQuery form validation script. Problem is, when I run validation on my form, it seems to work, but no email is sent. But when I disable validation, the email sends just fine. I am fairly new to JavaScript, and need some help pinpointing where my error is. Here is the code. Code: // BEGIN JAVASCRIPT $(function(){ //original field values var field_values = { //id : value 'name' : 'your name', 'email' : 'your email', 'yourmessage' : 'I would like to inquire about' }; //inputfocus $('input#name').inputfocus({ value: field_values['name'] }); $('input#email').inputfocus({ value: field_values['email'] }); $('textarea#yourmessage').inputfocus({ value: field_values['yourmessage'] }); //form validation $('form').submit(function validateForm(){ return false }); // removing this return false seems to mess up validation $('#submit').click(function(){ //remove classes $('#sendamessage input').removeClass('error').removeClass('valid'); //ckeck if inputs aren't empty var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; var fields1 = $('#sendamessage input[type=text],#sendamessage textarea'); var error = 0; fields1.each(function(){ var value = $(this).val(); if( value.length<2 || value==field_values[$(this).attr('id')] || ( $(this).attr('id')=='email' && !emailPattern.test(value) ) ) { $(this).addClass('error'); // css class $(this).effect("shake", { times:3 }, 50); error++; } else { $(this).addClass('valid'); // css class } }); if(!error) { // this is where I get confused. How do I make this send the form? alert('Data sent'); }); } }); }); // END JAVASCRIPT <form method="post" action="" onsubmit="return validateForm()" > <input type="hidden" name="ccf_customhtml" value="1" /> <input type="hidden" name="success_message" value="Thank you for filling out our form!" /> <input type="hidden" name="destination_email" value="dauidus@gmail.com" /> <input type="hidden" name="required_fields" value="" /> <label for="name">Name</label> <input type="text" name="name" id="name" value="your name" /> <label for="email">Email</label> <input type="text" name="email" id="email" value="your email" /> <label for="yourmessage">Your Message</label> <textarea name="yourmessage" id="yourmessage" value="I would like to inquire about" style="margin-bottom:20px;" />I would like to inquire about</textarea> <input class="send submit" id="submit" type="submit" value="" style="position: relative; bottom: -70px; left: 25px; " /> </form> I am using a WordPress plugin to automatically send the contents of the form to email. It works without the javascript enabled. But when I turn on JS the form gets validated, but no email is sent. Please let me know if I should include anything else here... I've been looking at this code so much that I'm having a hard time doing it with fresh eyes. The problem page is on http://new.dauidusdesign.com/contact/. FYI, I am also looking to make this work with the 'request a quote' link on the same page. Cheers! -Dave I like to figure out in my ready made For Loop it out puts a list of names and amounts I want to figure out how to put in a colour scheme. such as having every second row in yellow highlight? here is my code Code: <title>The Lighthouse</title> <link href="lhouse.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="list.js"></script> <script type="text/javascript"> total=0; for (var i=0; i<amount.length; i++) { total=total+amount[i]; } document.write(total); </script> </head> <body> <div id="title"> <img src="logo.jpg" alt="The Lighthouse" /> The Lighthouse<br /> 543 Oak Street<br /> Delphi, KY 89011<br/> (542) 555-7511 </div> <div id="data_list"> <script type="text/javascript"> document.write('<table'+' border="1"'+' rules="row"'+'cellspacing="0">'+'<tr>'+'<th>Date</th>'+'<th>Amount</th>'+'<th>First Name</th>'+'<th>Last Name</th>'+'<th>Address</th>'+'</tr>'); for (var i=0; i<date.length; i++){ document.write('<tr>'+'<td>'+date[i]+'</td>'+'<td>'+amount[i]+'</td>'+'<td>'+firstName[i]+'</td>'+'<td>'+lastName[i]+'</td>'+'</tr>');} </script> </table> </div> Any suggestions on how to add the colour within the loops How come this isn't working? document.getElementById('glance').style.display='block'.color='gold'; Hi i am trying to change the colour of the text in my menu bar, i know you can do this with css or jquery but i want to try and do it with javascript in an external script sheet. I want to use the onmouseover and onmouseout functions to change the colours, and i want it so their are different colours for each menu item. Can anybody help me? |