没有CSS,隐藏除第一张图像以外的所有图

时间:2017-01-08 18:30:23

标签: javascript jquery css

我正在this site工作,产品图片正在显示一些"颜色过滤"特征

问题是两个图像都是可见的,直到您将鼠标悬停在颜色框上,因为那时我的Javascript接管并显示/隐藏当前图像/颜色(请参阅底部的代码)。

我使用了一个名为Slimsy的插件给Umbraco 7,这使得cropUrl的响应能力很强但如果我在display: none容器上加.categoryImage它就不起作用,它必须是插件内的东西。

我需要在每个display: none容器上使用.categoryImage,但不知何故隐藏了除第一个以外的所有图像,所以插件可以确定宽度/高度/它需要的任何东西。

我的javascript:

$(".frameColor").each(function () {
    var categoryImage = $(this).parent("div").next("a").find(".categoryImage");
    categoryImage.first().show();

    if ($(categoryImage).length > 1) {
    $(this).on('mouseover', function () {
        var color = $(this).data('color').replace('#', '');

 $(".frameColor").removeClass("active");
        $(this).addClass("active");

        $(categoryImage).hide().filter(function () {
            return $(this).data('frame-color') === color;
        }).show();
    });
}
else {
    $(this).hide();
}

});

我的相框颜色

@foreach (var bikeColor in images)
                {
                    string color = bikeColor.GetPropertyValue("frameColor");
                    string[] colorSplit = color.Split(',');

                    if (colorSplit.Length == 1)
                {
                    <div class="frameColor" data-color="#@color" style="background-color:#@colorSplit[0]"></div>
                }
                else
                {
                    <div class="frameColor" data-color="#@color" style="background-image:linear-gradient(-30deg, #@colorSplit[0] 0%, #@colorSplit[0] 50%, #@colorSplit[1] 50%, #@colorSplit[1] 60%);"></div>
                }
            }

1 个答案:

答案 0 :(得分:1)

要定位除.frameColor之外的所有$.each(),在$(".frameColor:not(:first)").each(function () {}); 循环中,您可以

display: none;

要隐藏它们而不使用opacity: 0;,您可以使用visibility: hidden;class ContactPage extends Page { private static $db = array( 'TelCustomerSupport' => 'Varchar', 'TelProjectSupport' => 'Varchar', 'OfficeName' => 'Text', 'OfficeStreetAddress' => 'Text', 'OfficeAddressLocality' => 'Text', 'OfficePostalCode' => 'Varchar', 'OfficeMapLink' => 'Text', 'OfficeLatitude' => 'Text', 'OfficeLongitude' => 'Text', ); public function getCMSFields() { $fields = parent::getCMSFields(); // Add extra fields $fields->addFieldToTab("Root.Main", new TextField('TelCustomerSupport', 'Phone - Customer, Trade & Retail Support'), "Content"); $fields->addFieldToTab("Root.Main", new TextField('TelProjectSupport', 'Phone - Project Support'), "Content"); $fields->addFieldToTab("Root.Main", new TextField('OfficeName'), "Content"); $fields->addFieldToTab("Root.Main", new TextField('OfficeStreetAddress'), "Content"); $fields->addFieldToTab("Root.Main", new TextField('OfficeAddressLocality'), "Content"); $fields->addFieldToTab("Root.Main", new TextField('OfficePostalCode'), "Content"); $fields->addFieldToTab("Root.Main", new TextField('OfficeMapLink'), "Content"); $fields->addFieldToTab("Root.Main", new TextField('OfficeLatitude'), "Content"); $fields->addFieldToTab("Root.Main", new TextField('OfficeLongitude'), "Content"); return $fields; } } class ContactPage_Controller extends NetSuitePage_Controller { private static $allowed_actions = array('ContactForm'); // Generate the form public function ContactForm() { // Create fields $fields = new FieldList( TextField::create("FirstName")->setTitle(_t('Contact.FIRSTNAME')), TextField::create("LastName")->setTitle(_t('Contact.LASTNAME')), EmailField::create("Email")->setTitle(_t('Contact.EMAILADDRESS')), TextField::create("Phone")->setTitle(_t('Contact.PHONENUMBER')), DropdownField::create('Iam', _t('Contact.IAMA'), $this->translateNetsuiteConfigArray('Contact', 'Iam')), TextField::create("SendSubject")->setTitle(_t('Contact.SUBJECT')), HoneyPotField::create("Subject2")->setTitle('Subject2'), TextareaField::create("Message")->setTitle(_t('Contact.MESSAGE'))->setColumns(30)->setRows(10) new RecaptchaField('MyCaptcha') ); // Create actions $submitbutton = new FormAction('doContactForm', _t('Contact.SEND')); $submitbutton->addExtraClass('btn btn-black'); $actions = new FieldList( $submitbutton ); $validator = ZenValidator::create(); $validator->addRequiredFields(array('FirstName', 'LastName', 'Email', 'Phone', 'Iam', 'SendSubject', 'Message')); $validator->setConstraint('FirstName', Constraint_length::create('max', 32)); $validator->setConstraint('LastName', Constraint_length::create('max', 32)); $validator->setConstraint('Phone', Constraint_length::create('min', 7)); $validator->setConstraint('Email', Constraint_type::create('email')); $validator->setConstraint('Phone', Constraint_type::create('digits')); $form = new Form($this, 'ContactForm', $fields, $actions, $validator); $form->addExtraClass('contact-form'); $form->setFormMethod('POST', true); return $form; } // Deal with form submission public function doContactForm($data, $form) { $submission = new ContactFormSubmission(); $form->saveInto($submission); $submission->write(); $data['path'] = print_r($this->refererTracker->retrieveAll(), true); $email = new Email(); $email->setTemplate('ContactFormEmail'); $email->populateTemplate($data); $email->setTo($this->getNetsuiteConfig('Contact', 'Emails')); $email->setFrom("no-reply@warmup.co.uk"); $email->setSubject('[warmup.co.uk] New contact from the website'); $email->populateTemplate($data); $email->send(); $post = $this->getNetsuiteConfig('Contact'); $post->firstname = $data['FirstName']; $post->lastname = $data['LastName']; $post->email = $data['Email']; $post->phone = $data['Phone']; $post->custentity116 = $data['Iam']; $post->custentitysubject_contact_us = $data['SendSubject']; $post->custentitymessage_contact_us = $data['Message']; // Check for success if ($this->queueNetSuitePost($post)) { return $this->redirect(Director::get_current_page()->Link()."?success=1"); } // Redirect back with form data and error message Session::set('FormInfo.' . $form->FormName() . '.data', $data); Session::set('FormInfo.'.$form->FormName().'.errors', array()); $form->sessionMessage("Netsuite error", 'bad'); return $this->redirectBack(); } // Returns true if form submitted successfully public function Success() { return isset($_REQUEST['success']) && $_REQUEST['success'] == "1"; } public function getCurrentSubsite() { $subsite = Subsite::currentSubsite(); if($subsite) { return $subsite->Title; } return $subsite; } }