position - Reposition jQuery alert -
wondering how reposition jquery alert in form below. pops @ top of browser, under address bar. nice have closer center of screen if @ possible. inexperienced jquery appreciated.
thank in advance! susan
{% if template contains 'product' , product.available %} <script> jquery('form[action^="/cart/add"]').submit(function() { var product = {{ product | json }}, cannotaddthisquantity = false, message = 'so sorry! must have gotten last one! not have more %t in stock.', selectedvariantid = jquery(this).find('[name="id"]').val(), quantitytoadd = parseint(jquery(this).find('[name="quantity"]').val(), 10) || 1, quantityincart = 0, title = ''; inventorylimited = false, inventory = 0; (var i=0; i<product.variants.length; i++) { if (product.variants[i].id == selectedvariantid) { var variant = product.variants[i];; title = product.title; if (product.variants.length > 1) title += ' - ' + variant.title; if (variant.inventory_management && variant.inventory_policy == 'deny') { inventorylimited = true; inventory = product.variants[i].inventory_quantity; } } } if (inventorylimited) { {% if cart.item_count > 0 %} var cart = {{ cart | json }}; (var i=0; i<cart.items.length; i++) { if (cart.items[i].id == selectedvariantid) { quantityincart = cart.items[i].quantity; } } {% endif %} if ((inventory - quantityincart) < quantitytoadd) { message = message.replace('%q', quantitytoadd).replace('%t', title); if (quantitytoadd > 1) message.replace('item', 'items'); cannotaddthisquantity = true; } } if (cannotaddthisquantity) { alert(message); return false; } else { return true; } }); </script>
instead of using alert(), put 'message' custom div , can position wherever want
jquery
if (cannotaddthisquantity) { $('.myalertdiv').html(message).fadein(); return false; }
css
.myalertdiv{ position: absolute; top: 100px; left: 100px; display: none; *etc...* }
obviously change css whatever want . . .
Comments
Post a Comment